Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #994681

    Hi,
    I’ve got a MemberPress setup on my site, that uses a rule that says, ‘Posts with category of ‘this’ type, can only be viewed by people with Memberships of ‘this’ type.

    So my category schema looks something like:
    Themes (Parent Category)
    – Category 1 (eg. ‘home renovating’)
    – Category 2 (eg. ‘home demolishing’)
    Membership (Parent Category)
    – Membership Grp 1 (eg. ‘builders’)
    – Membership Grp 2 (eg. ‘home owners’)

    Example scenario:
    Membership Grp 2 creates a post with the following categories ticked;
    – ‘home demolishing’ (no Membership required)
    AND
    – ‘home owners’ (‘home owners’ makes it a Membership Grp 2 only Post).

    Membership Grp 1 has a Post Slider on their Membership Home Page that has ‘home demolishing’ and ‘builders’ as the selected categories.

    Problem that needs solving:
    The Grp1 Membership Page Post Slider will be displaying content that requires Grp2 Membership because it doesn’t have conditions on which categories to display.

    My Question:
    Is there a way to make it that the Post slider ONLY displays Posts with;
    ‘home demolishing’ AND ‘builders’ (Grp1)
    Instead of the current unconditional setting of displaying;
    ‘home demolishing’ OR ‘builders’ OR any other category that’s selected.

    Hope that all makes sense… and look forward to hearing your thoughts!

    TD

    • This topic was modified 5 years, 9 months ago by Divers1fy.
    #994828

    Hey Divers1fy,

    You can use the avia_post_slide_query filter to alter the query.

    Use it like:

    
    add_filter('avia_post_slide_query', 'avia_post_slider_custom_query', 10, 2);
    
    function avia_post_slider_custom_query( $query, $params ) {
    $include_cat = array('category__and' => array( 2, 6 ));
    $query = array_merge((array)$include_cat, (array)$query);
    return $query;
    }
    

    Insert this code into the child theme functions.php file and replace 2, 6 with the category ids of your categories ‘home demolishing’ AND ‘builders’.

    You can use the css class field to apply the code to certain post slider elements only.

    1) Activate the css class option field: https://kriesi.at/documentation/enfold/intro-to-advanced-layout-builder/#turn-on-custom-css-class-field-for-all-alb-elements

    2) Insert the css class “avf_filter_post_slider_cats” (without the quotes) into the field (post slider element you want to filter)

    3) Save the elements/page

    4) Add this code to the funtions.php file

    
    add_filter('avia_post_slide_query', 'avia_post_slider_custom_query', 10, 2);
    function avia_post_slider_custom_query( $query, $params ) {
    	if(!empty($params['class']) && strpos($params['class'], 'avf_filter_post_slider_cats') !== false)
    	{
    		$include_cat = array('category__and' => array( 2, 6 ));
    		$query = array_merge((array)$include_cat, (array)$query);
    	}
    	return $query;
    }
    

    and replace 2, 6 with your category ids.

    Best regards,
    Dude

    #995193

    Hi Dude,

    Well, that’s taking it all to a whole new level… great stuff! Thanks for that. I’ll give it a go over this weekend and see how it flies. Again, thanks for your time and efforts.

    Cheers,

    TD

    #995587

    Hi Divers1fy,

    Glad Dude could help you :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.