I’d like to sort posts on the index page to show those that have a featured image first.
I’ve done this in functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() || is_archive() ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', '_wp_attached_file');
}
}
The causes no posts to be shown on the index page.
What should I be doing here?
Change
_wp_attached_file
to_thumbnail_id