[Resolved] WP Show Posts: Sticky posts NOT ignored when Taxonomy selected

Home Forums Support [Resolved] WP Show Posts: Sticky posts NOT ignored when Taxonomy selected

Home Forums Support WP Show Posts: Sticky posts NOT ignored when Taxonomy selected

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1927437
    Rafał

    Hi there!
    This thread on WP Support has been closed unresolved → “If Taxonomy is by Category, sticky posts are ignored“, however, for almost 2 years there was no update that would fix this issue.
    Any hacky workaround? Please…

    #1928207
    Elvin
    Staff
    Customer Support

    Hi Rafal,

    The issue has something to so w/ WordPress’ core function WP_query().

    It doesn’t allow sticky posts for archive pages (queries w/ specified taxonomy).

    You can even test this out yourself by assigning a sticky post and check if it goes first on the list on its own category/tag archive page.

    But as for workaround, I’d steer away from using WordPress default’s way of assigning sticky posts. I’d use a custom field to assign if a post is a sticky post and then use this as meta_key and meta_value for orderby on the query.

    also, I’d make 2 of the same category post lists stacking on top of each other.

    The first list will be strictly for posts of the same category that have “sticky” indicated through its custom field.

    The second list will be strictly for posts of the same category that excludes posts that have “sticky” indicated through its custom field to avoid duplicate posts.

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

    #1928550
    Rafał

    Hi Elvin,
    Thank you for your clever workaround. I’m afraid it would be handy in a small project, but not at website where many posts are published each day, by many users.
    If only we could stay with Meta key / Meta value for sticky posts, but we have to assign the meta for every posttrue or false – haven’t we?

    #1929200
    Rafał

    Please, let me come back to the WP “native-sticky-inconvenience-in-archives”. I admit, it takes place in standard outputs.

    However, what do you think about the new Query Block (from WP 5.8), which can maintain sticky posts very well. You may: include, exclude, or show only sticky posts!

    Unfortunately, the biggest performance problem is here—you can’t choose featured image size (only the full one).

    On the other hand, Latest Posts widget allows to choose image size, but lacks other crucial options.

    #1929619
    Elvin
    Staff
    Customer Support

    To clarify, do we have to simply include the sticky post or must we have it show as the first post on the list?

    If its just including sticky posts to the post list, that’s something we can do w/ WPSP.

    But if its making the sticky post as the first post on the category query. I don’t think wp_query does that. Even the Query block can’t do it. (it will include the sticky post but it will follow the orderby value of the query and NOT put the sticky post on the top of the list)

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

    #1929672
    Rafał

    In my case the aim is to exclude sticky posts in a single category list (there are many blocks – per each category). Sticky post is highlighted in a separate block.

    #1929714
    Elvin
    Staff
    Customer Support

    Ah in that case try this:

    Use our beta version of the WPSP plugin – https://github.com/tomusborne/wp-show-posts/tree/release/1.2

    and then do this PHP filter. (replace 10 on the line if ( 10 === (int) $settings['list_id'] ) with your target WPSP ID)

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 10 === (int) $settings['list_id'] ) {
    		$sticky = get_option( 'sticky_posts' );
    		$args['post__not_in'] = $sticky;
        }
    
        return $args;
    }, 20, 2 );

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

    #1929942
    Rafał

    That’s it!!!
    Works for me 🙂
    Thank you, Elvin!

    PS
    I’d recommend to implement your filter into official release of WPSP, under the hood of checkbox “Ignore sticky posts“.

    #1930795
    Elvin
    Staff
    Customer Support

    PS
    I’d recommend to implement your filter into official release of WPSP, under the hood of checkbox “Ignore sticky posts“.

    Yeah that’s actually what its supposed to do but it doesn’t apply when the query has taxonomy. It’s toggling true or false on 'ignore_sticky_posts'.

    I’ve logged it as an issue on our GitHub page for the next patch. 😀
    https://github.com/tomusborne/wp-show-posts/issues/41

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

    #1930915
    Rafał

    Thanks a lot!

    Regards & respect

    #1930921
    Elvin
    Staff
    Customer Support

    No problem. Glad to be of any help. 😀

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

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