tax_query and sort by meta_key – no results

I have query:

$tax_query = array(
‘relation’ => ‘AND’);
$tax_query[] = array(
‘taxonomy’ => ‘kategoria’,
‘field’ => ‘id’,
‘terms’ => $term->term_id,
);
if($_GET[‘kolor’]) {
$tax_query[] = array(‘taxonomy’ => ‘kolor’, ‘field’ => ‘slug’, ‘terms’ => $_GET[‘kolor’]);
}
$query = new WP_Query( array( ‘post_type’ => ‘produkt’, ‘posts_per_page’ => 1000, ‘tax_query’ => $tax_query, ) );

And this works great, but I want to add sorting by custom field, so I edit query to the next one:

$query = new WP_Query( array( ‘post_type’ => ‘produkt’, ‘posts_per_page’ => 1000, ‘tax_query’ => $tax_query, ‘meta_key’ => ‘kolejnosc’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ) );

And this isn’t working, result is just one item, when there’s a lot more.

Read more here:: tax_query and sort by meta_key – no results

Leave a Reply

Your email address will not be published. Required fields are marked *