Is there a way to query all pages and order them by menu_order
but ignore those pages that the default value of 0
?
I was trying to do something like this:
$the_query = array(
'post_type' => self::POST_TYPE,
'posts_per_page' => $total,
'product_cat' => $product_category_name,
'orderby' => $orderby,
'suppress_filters' => '0'
);
Or do I need to create a filter to alter the WP_Query
? any ideas?
cheers
You can try the following (untested) mini plugin:
<?php
/**
* Plugin Name: Support for ignoring the default menu order in WP_Query
* Description: Uses the _ignore_default_menu_order argument
* Plugin URI: http://wordpress.stackexchange.com/a/193291/26350
*/
add_filter( 'posts_where', function( $where, $q )
{
global $wpdb;
if( (bool) $q->get( '_ignore_default_menu_order' ) ) {
$where .= "AND {$wpdb->posts}.menu_order <> 0";
}
return $where;
}, 10, 2 );
Then you should be able to use the new custom query argument like:
$query = new WP_Query(
[
'_ignore_default_menu_order' => true,
]
);
to ignore posts with the default menu order (0
).
You could also extend this to support any menu order as user input.