Im using the pre_get_posts hook to customize my query for a custom post type archive.
Some of the posts for this custom post type have a meta key mp_micropub_accredited with the meta value of 1 and others don't have this meta key set.
I use the following code,
function micropubs_filter_posts( $query ) { if ( !is_admin() && $query->is_post_type_archive( 'micropubs' ) && $query->is_main_query() ) { $query->set( 'posts_per_page', 5 ); $accredited = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING ); if ( empty( $accredited ) ) return; if ( $accredited === 'accredited' ) { $query->set( 'meta_key', 'mp_micropub_accredited' ); $query->set( 'orderby', 'meta_value_num' ); } } } add_action( 'pre_get_posts', 'micropubs_filter_posts' );
So when i locate to this address in my browser it displays only the posts with the meta key set and no other posts.
http://localhost/site/post-type-archive/?orderby=accredited
How is it possible to include all the other posts that don't have the mp_micropub_accredited meta key set but are displayed after the ones that are?
Your help much appreciated. :)