I'm trying to order the main query on the 'Jobs' post type archive page. I want to order them by a meta_key so the ones which have a value (i.e. are checked as Featured') are shown first. Here's what I have at the moment..
function featured_jobs_order( $orderby ) {
if( !is_post_type_archive('jobs') ) {
return $orderby;
}
global $wpdb;
$orderby = $wpdb->postmeta . '.meta_value DESC, ' . $orderby;
return $orderby;
}
add_filter('posts_orderby', 'featured_jobs_order' );
function change_jobs_query( $query ) {
if ( is_post_type_archive( 'jobs' ) ) {
$query->set( 'meta_key', 'featured' );
return;
}
}
add_action( 'pre_get_posts', 'change_jobs_query', 1 );
At the moment it only brings back the ones that are featured and doesn't bring back the rest at all.
Cheers, Steve