Support

Account

Home Forums General Issues Order archive based on custom post object metakey value Reply To: Order archive based on custom post object metakey value

  • Hi Steve,

    You can’t do what you’re asking just by modifying the wp_query with pre_get_posts.. Atleast not by querying artwork.

    However, you can instead of directly querying artwork and trying to order those query the artists.
    So you would do a custom wp_query for all artists and order them by their lastname like so:

    
    $args = array(
    'post_type' => 'artist',
    'orderby' => 'meta_value',
    'meta_key' => 'surname',
    'posts_per_page' => -1
    );
    

    Then as you loop through each artist you query their artwork (inside the artist loop).

    
    $artist_ID = get_the_ID();
    $artwork_args = array(
    	'post_type' => 'artwork',
    	'posts_per_page' => -1,
    	'meta_query' => array(
    		array(
    			'key' => 'artist_dropdown',
    			'value' => $artist_ID,
    			'compare' => '='
    		)
    	)
    );