[wp-forums] sorting posts per title using 'pre_get_posts'
Michael Stolze
alchymyth at gmail.com
Mon May 20 12:34:26 UTC 2013
thanks, Chris; I ended up using:
function wpsf_orderby( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
// do conditional checks here and return on false.?
if ( is_category('uncategorized') ) {
remove_action( 'pre_get_posts', __FUNCTION__ );
add_filter( 'posts_orderby', function() { return ' post_title ASC'; } );
}
}
add_action( 'pre_get_posts', 'wpsf_orderby' );
(hopefully this resolves the topic)
thanks again,
Michael aka alchymyth
On 20 May 2013 13:00, <wp-forums-request at lists.automattic.com> wrote:
>
> Today's Topics:
>
> 1. Re: sorting posts per title using 'pre_get_posts' (Michael Stolze)
> 2. Re: sorting posts per title using 'pre_get_posts' (Chris Olbekson)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 19 May 2013 20:53:34 +0100
> From: Michael Stolze <alchymyth at gmail.com>
> To: wp-forums at lists.automattic.com
> Subject: Re: [wp-forums] sorting posts per title using 'pre_get_posts'
> Message-ID:
> <
> CAGF886KyF9-E7o53MW2f6B+R9Ln6sTrcA9G8PoYOiukiJZ1rog at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> 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
>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 19 May 2013 14:54:23 -0700 (PDT)
> From: "Chris Olbekson" <chris at c3mdigital.com>
> To: wp-forums at lists.automattic.com
> Subject: Re: [wp-forums] sorting posts per title using 'pre_get_posts'
> Message-ID: <1369000461949.cbdaa37e at Nodemailer>
> Content-Type: text/plain; charset=utf-8
>
> 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
>
>
>
More information about the wp-forums
mailing list