Reorder post within categories with $wp_query in other plugin
-
Hello
since I struggled to make it works, I share my solution :
I found the add_filter method and the generated query “join” fine but didn’t “order”.
It’s just a matter of priority of the posts_orderby filter that wasn’t high enough.
I’m using the List Category Post Plugin to get posts from a specific category I intended to order manualy thanks to this plugin.
Here is my working code :global $wp_query, $wpdb; function filter_join($join){ global $wp_query, $wpdb; $join .= " LEFT JOIN ".$wpdb->prefix."reorder_post_rel ON (".$wpdb->prefix."posts.ID = ".$wpdb->prefix."reorder_post_rel.post_id AND ".$wpdb->prefix."term_relationships.term_taxonomy_id = ".$wpdb->prefix."reorder_post_rel.category_id )"; return $join; } function edit_posts_orderby($orderby){ global $wp_query, $wpdb; $orderby = " ".$wpdb->prefix."reorder_post_rel.id "; return $orderby; } add_filter('posts_join', 'filter_join'); add_filter('posts_orderby', 'edit_posts_orderby',1000); $wp_query->query; remove_filter('posts_join', 'filter_join'); remove_filter('posts_orderby', 'edit_posts_orderby');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Reorder post within categories with $wp_query in other plugin’ is closed to new replies.