[wp-forums] sorting posts per title using 'pre_get_posts'
Chris Olbekson
chris at c3mdigital.com
Sun May 19 21:54:23 UTC 2013
I'm on mobile and can't reply to thread.
To solve he would need to use the posts_orderby filter. The problem is posts _orderby doesn't know anything about $wp_query. The solution is to add the filter from within the wrapper function from pre_get_posts.
function wpsf_orderby( $query ) {
// do conditional checks here and return on false.
remove _action( 'pre_get_posts', __FUNCTION__ );
add_filter( 'posts_orderby', function() {
return 'ORDER BY post_title ASC';
}
}
add_action( 'pre_get_posts', 'wpsf_orderby' );
-
Chris Olbekson
WordPress Developer
X-Team "X-Terminator"
X-team.com
Sent from my iPhone
On Sun, May 19, 2013 at 2:53 PM, Michael Stolze <alchymyth at gmail.com>
wrote:
> I am at the end of what to suggest or ask in this topic:
> http://wordpress.org/support/topic/sort-posts-alphabetically-1?replies=9
> code is tested in Twenty Twelve.
> maybe one of you has an idea?
> thanks,
> Michael
> _______________________________________________
> wp-forums mailing list
> wp-forums at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-forums
More information about the wp-forums
mailing list