samedi 31 janvier 2015

If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?


So I have 3 custom post types that I want to order by menu_order & have 'date' as the fallback parameter as the majority of posts will have the default menu order of '0'.


It would be nice if pre_get_posts would do this relatively simply (as opposed to something like this - Multiple orderby parameters in pre_get_posts() action), but not looking probable.


This works fine with posts where menu order is set to specific value, where it is 0, the order seems mostly random:



function order_cpt( $query ) {

if ( !is_admin() && $query->is_post_type_archive( array ( 'cat1', 'cat2', 'cat3' ) && query->is_main_query() ) {
$query->set( 'orderby', 'menu_order');
$query->set( 'order', 'DESC' );
return $query;
}
}
add_action( 'pre_get_posts', 'order_cpt');


So the first question which I can't seem to find an answer for is - how are the posts with the same menu order actually being dealt using the function above?


And is pre_get_posts the best route or should I be looking at a custom WP_Query?


Thanks





Aucun commentaire:

Enregistrer un commentaire