[Resolved] display rules – location – post category

Home Forums Support [Resolved] display rules – location – post category

Home Forums Support display rules – location – post category

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

    Hi,

    I’ve added a hook affiliate disclaimer that I want to appear on any post with the category ‘products’ that I have. I’ve set this up and see that it doesn’t work on the top-level category tag. For instance, I have a top level category ‘products’ then underneath I have numerous nested categories, and I only see the hook appear when i put it on the bottom level nested category. Is there a way to adjust the display rules so that it will display on all categories under the main product category or do i have to put the display rule for each nested category underneath it?

    I’m not sure if this makes sense but i’ve added some screenshots to help illustrate this.

    Thanks

    #2328355
    David
    Staff
    Customer Support

    Hi there,

    so we want to check if the current post has a category term that is a child of products.
    Currently you would either need to:

    a. Set each of the Post Category -> Child terms in the Element Display Rules

    OR

    b. Use the generate_element_display filter hook to set element display to True if the posts are in child term

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        /// Change 123 below to the ID of the Element we're targeting.
        if ( 123 === (int) $element_id ) {
            $args = array(
                'include'  => get_the_ID(),
                'category' => 456, // Change 456 to the parent category ID we're checking for children in.
                'fields'   => 'ids',
            );
    
            if ( 0 < count( get_posts( $args ) ) ) {
                $display = true;
            }
        }
    
        return $display;
    }, 10, 2 );

    Note the two IDs that need changing

    #2328519
    a1reno

    Hi David,

    I decided to go with the first option and just fill all the categories one by one in the rules.

    Thanks for your help!

    #2328525
    David
    Staff
    Customer Support

    You’re welcome

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