[Support request] Featured category post

Home Forums Support [Support request] Featured category post

Home Forums Support Featured category post

Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #1932302
    Elvin
    Staff
    Customer Support

    However, as you pointed out there are 2 queries on the page. On the green background where all the posts for the category are listed, the problem is that the featured post is showing there too. Is there a way to automatically exclude the featured post from the green background area?

    It’s not ideal to mess with that as this page is the default archive page WordPress generates that is meant to list ALL posts that are under category “popular”, regardless of what other category or tags they have.

    But if you really must do it, you can try going with pre_get_post filter.

    Example:

    function exclude_with_post_tag_on_cat_archive( $query ) { 
        $category = get_queried_object();
        $cat_id = $category->term_id;	
        $cat_slug = $category->slug;
        $featured_tag = 'featured-' . $cat_slug;
        $tag_id = get_term_by('slug', $featured_tag ,'post_tag');
    
        if ( $query->is_category($cat_id) && $query->is_main_query() ) {  
    
            $query->set( 'tag__not_in', array( $tag_id ) ); 
    
        } 
    
    } 
    
    add_action( 'pre_get_posts', 'exclude_with_post_tag_on_cat_archive' );
    #1932974
    Vicky

    Hi Elvin,

    Thanks for all your help on this, I appreciate that I’m asking for an unusual solution here!

    Unfortunately, that last bit of code didn’t work out, the featured post is still showing up in the 2nd query. I think I’ll probably have to go back and rethink my design!

    Thanks anyway,
    Vicky

    #1933278
    Elvin
    Staff
    Customer Support

    No problem. 😀

Viewing 3 posts - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.