[Resolved] archive sticky post

Home Forums Support [Resolved] archive sticky post

Home Forums Support archive sticky post

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #1981516
    Elvin
    Staff
    Customer Support

    Hi Benjamin,

    If it’s for ALL the tag archives, you’ll have to do it like this:

    function exclude_posts( $query ) { 
        if ( is_feed() ) {
            return $query;
        }
        if ( $query->is_tax() ) {
            $query->set( 'tag__not_in', array( 2414 ) ); 
        }
        return $query;
    } 
    
    add_action( 'pre_get_posts', 'exclude_posts' );

    A wise man once said:
    "Have you cleared your cache?"

    #1999101
    Benjamin

    I mean just on a specific tag archive page. In this case I have a tag called LMUTW (id 2178), and I have created a matching tag called LMUTW Spotlight (2414). I’d like to exclude any post tagged LMUTW Spotlight from the LMUTW archive, so I can place the spotlight post in a Showpost/spotlight box at the top of the page.

    #1999345
    Elvin
    Staff
    Customer Support

    Try this:

    function exclude_posts( $query ) { 
        if ( is_feed() ) {
            return $query;
        }
        if ( $query->is_tag(2178) ) {
            $query->set( 'tag__not_in', array( 2414 ) ); 
        }
        return $query;
    } 
    
    add_action( 'pre_get_posts', 'exclude_posts' );

    This checks if the current page is an archive page of post tag ID 2178. If yes, it will exclude posts w/ tag id 2414.

    A wise man once said:
    "Have you cleared your cache?"

    #1999360
    Benjamin

    Ah, that’s just the outcome I want! But it’s throwing a fatal error for the site…. :-/

    #1999371
    Benjamin

    Which may be because of another, identically named function. I have renamed this new one to function exclude_lmutwposts, however it doesn’t seem to be doing the trick :-p https://newsmigstg.wpengine.com/tag/lmutw/

    #1999375
    Elvin
    Staff
    Customer Support

    Can you try this instead?

    function exclude_posts( $query ) { 
        if ( is_feed() ) {
            return $query;
        }
        if ( $query->is_main_query() && is_tag( 2178 ) ) {
            $query->set( 'tag__not_in', array( 2414 ) ); 
        }
        return $query;
    } 
    
    add_action( 'pre_get_posts', 'exclude_posts' );

    This one should work 100%.

    A wise man once said:
    "Have you cleared your cache?"

    #1999376
    Benjamin

    Sorry for spamming you. User error. I needed to rename it in two places. Done, and seems to work! Thank you!

    #1999378
    Elvin
    Staff
    Customer Support

    Sorry for spamming you. User error. I needed to rename it in two places. Done, and seems to work! Thank you!

    Ah you probably had a duplicate function name. Glad you got it sorted. No problem.

    A wise man once said:
    "Have you cleared your cache?"

    #2130175
    Brad

    This is pretty cool idea. Amazing you got it to work.

    #2131396
    Elvin
    Staff
    Customer Support

    @Brad, let us know if you need help with something like this as well.

    A wise man once said:
    "Have you cleared your cache?"

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