• How can I change the sort order for my custom post type archive using pre_get_posts, when the SQL would be:

    ORDER BY wp_postmeta.meta_value ASC, wp_posts.ID DESC

    if(
    	! is_admin() &&
    	is_post_type_archive('fsbo') &&
    	$query->is_main_query()
    )
    {
    	$query->set( 'orderby', 'wp_postmeta.meta_value ASC, wp_posts.ID DESC' );
    }

    The sort order is not right when I use this.

Viewing 1 replies (of 1 total)
  • Thread Starter skunkbad

    (@skunkbad)

    I figured it out. Just put the things to order by in an array:

    if(
    	! is_admin() &&
    	is_post_type_archive('fsbo') &&
    	$query->is_main_query()
    )
    {
    	$query->set('meta_key', '_fsbo_status');
    	$query->set('orderby', ['meta_value' => 'ASC', 'ID' => 'DESC']);
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Sort order for archive of custom post type’ is closed to new replies.