- This topic has 14 replies, 2 voices, and was last updated 4 years ago by
Elvin.
-
AuthorPosts
-
September 12, 2021 at 1:29 am #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…September 12, 2021 at 6:20 pm #1928207Elvin
StaffCustomer SupportHi 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.
September 13, 2021 at 2:10 am #1928550Rafał
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 post –true
orfalse
– haven’t we?September 13, 2021 at 10:19 am #1929200Rafał
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.
September 13, 2021 at 8:54 pm #1929619Elvin
StaffCustomer SupportTo 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)
September 13, 2021 at 10:33 pm #1929672Rafał
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.
September 13, 2021 at 11:33 pm #1929714Elvin
StaffCustomer SupportAh 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 lineif ( 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 );
September 14, 2021 at 4:07 am #1929942Rafał
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“.September 14, 2021 at 7:10 pm #1930795Elvin
StaffCustomer SupportPS
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/41September 14, 2021 at 10:42 pm #1930915Rafał
Thanks a lot!
Regards & respect
September 14, 2021 at 10:46 pm #1930921Elvin
StaffCustomer SupportNo problem. Glad to be of any help. 😀
October 4, 2021 at 10:16 am #1952443Rafał
If someone would like to go along my scenario:
WPSP with ID888
shows sticky only, all other lists exclude sticky posts.add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 888 != (int) $settings['list_id'] ) { $sticky = get_option( 'sticky_posts' ); $args['post__not_in'] = $sticky; } if ( 888 === (int) $settings['list_id'] ) { $sticky = get_option( 'sticky_posts' ); $args['post__in'] = $sticky; } return $args; }, 20, 2 );
October 4, 2021 at 7:06 pm #1952741Elvin
StaffCustomer SupportNot sure what’s the question here. Is the code not working?
Can you explain what’s the aim of the code? Let us know.
October 4, 2021 at 10:26 pm #1952854Rafał
Is working! Thanks to you, Elvin.
Just share my solution 🙂October 4, 2021 at 10:37 pm #1952861Elvin
StaffCustomer SupportOh nice one! Thanks for sharing it with us. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.