WP_Query
它本身无法在内部执行该逻辑,但您可以轻松地动态创建查询。
$args = array(
\'meta_key\' => \'name\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'posts_per_page\' => \'-1\'
);
if ($post->ID == 1) {
$args[\'category_name\'] = \'first\';
} elseif ($post->ID == 2) {
$args[\'category_name\'] = \'second\';
}
$custom_loop = new WP_Query($args);