Sticky Post functionality with WP_Query is ignored when using AJAX
-
Hello everyone,
I am writing custom ajax pagination for a Blog archive page and I am running into an issue with sticky posts.
The default functionality of sticky posts when using a WP_Query call is to sort all sticky posts at the top, unless explicitly stated otherwise.
My AJAX is functioning correctly with no errors and displays the requested posts correctly without issue and can be sorted by category and feature pagination (using posts_per_page and offset).
The only problem is that the posts retrieved are not listing sticky posts in the front but rather in their natural order. The correct group of posts are queried but they do not order correctly.
My argument is:
$args = array( 'posts_per_page' => 10, 'order' => 'DESC', 'cat' => (php value retrieved from AJAX, so it changes based on user input), 'offset' => (determined via data attributes to calculate page number. $offset = ( current_page_number - 1 ) * posts_per_page ) ) $blog_posts = new WP_Query( $args );If I print_r $blog_posts, the order of the posts is in its default order (much like if you were to use get_posts instead of WP_Query )
If I use this exact query on any page (or post, custom post type post, archive, etc), the WP_Query function returns in the correct order with sticky posts on top.
Is this a bug anyone else has run into? The code runs fine, I am wondering if this is a WordPress core bug?
Thanks
The topic ‘Sticky Post functionality with WP_Query is ignored when using AJAX’ is closed to new replies.