Multiple meta_key | WordPress.org

[ad_1]

I want to sort my cars by two custom fields but can’t get this working properly.

So the primary field would be has_photos order by DESC this never change (I get this one).

The issue is… users can also sort by Price (Low/High) and I can’t find a way to add both custom fields to the sort criteria… but I can only use one of them “price or has_photo”.

		'meta_key' => $meta_key,
		'orderby' => [$meta_value_text => $meta_value]);

I also tried something like this:

	$arg = array('posts_per_page' => $posts_per_page,
		'paged' => $paged,
		'post_type' => 'inventory',
		'meta_query' => array(
			array(
                'key'     => 'has_photos',
                'orderby' => 'meta_value',
                'order' => 'DESC',
            ),
            array(
                'key'     => $meta_key,
                'orderby' => $meta_value_text,
                'order' => $meta_value,
            ),
			'relation' => 'AND', $filter));

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer