按自定义分类法订购WP帖子

My query needs to order the posts by a Custom Taxonomy called "markets", but the query lists the posts order by a "meta_value" called "state". These should be also sorted by "markets".

Here is the code:

$query_args = array(
    'post_type'      => $post_type,
    'posts_per_page' => 50,
    'post_status'    => 'publish',
    'tax_query'      => array(
        array(
            'taxonomy' => $taxonomy,
            'terms'    => $type,
            'field'    => 'slug',
        ),
    ),
    'meta_key'      => 'state',
    'orderby'       => 'meta_value',
    'order'          => 'asc',
);

$query = new WP_Query( $query_args );
  • $post_type is a custom post type.
  • $taxonomy is an custom taxonomy called "types".
  • $type is the type that I need to query, for example: "multimedia".

For example, some results get:

California

  • San Diego - (this is the market, this contains a specific title and other data)
  • Monterey - (idem)
  • Monterey - (idem)
  • Monterey - (idem)
  • San Diego - (idem)

and these should be:

California

  • Monterey - (idem)
  • Monterey - (idem)
  • Monterey - (idem)
  • San Diego - (idem)
  • San Diego - (idem)

That is order by "market"

So, this query gets the posts for a custom post type where the taxonomy is "multimedia", ordered by the states. Also I need order these results by "markets" taxonomy ASC.