我有一个自定义WP\\U查询调用,我想按一个自定义字段显示CPT,并按另一个自定义字段排序:
$args = array(
\'post_type\' => \'nehnutelnost\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'order\' => \'ASC\',
\'meta_key\' => \'podlazie\',
\'meta_value\' => \'2_nadzemne_podlazie\',
\'meta_compare\' => \'LIKE\',
\'meta_key\' => \'cislo_bytu\',
\'orderby\' => \'meta_value\',
);
$query = new WP_Query( $args );
SO网友:Arafat Jamil
$q = new WP_Query( array(
\'meta_query\' => array(
\'relation\' => \'AND\',
\'state_clause\' => array(
\'key\' => \'state\',
\'value\' => \'Wisconsin\',
),
\'city_clause\' => array(
\'key\' => \'city\',
\'compare\' => \'EXISTS\',
),
),
\'orderby\' => array(
\'city_clause\' => \'ASC\',
\'state_clause\' => \'DESC\',
),
) );
您可以使用此查询进行排序,即使有多个元键。这些称为子查询。
请查看codex的此链接-https://developer.wordpress.org/reference/classes/wp_meta_query/