我正在使用WordPress 3.5。我的问题是,
$args = array(
\'post_type\' => array(\'product\', \'comic\', \'magazine\'),
\'taxonomy\' => \'Genres\',
\'term\' => \'hot\',
\'posts_per_page\' => 10
);
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
endwhile;
// Restore original Query & Post Data
wp_reset_query();
wp_reset_postdata();
这给出了我想要的确切结果但是,
$args = array(
\'post_type\' => array(\'product\', \'comic\', \'magazine\'),
\'taxonomy\' => \'Genres\',
\'term\' => array(\'hot\',\'home\'),
\'posts_per_page\' => 10
);
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
endwhile;
// Restore original Query & Post Data
wp_reset_query();
wp_reset_postdata();
这不起作用。
SO网友:cjbj
我有点惊讶第一个会起作用,因为它terms
, 不term
. 无论如何the correct way 为此,请执行以下操作:
$args = array(
\'post_type\' => array(\'product\', \'comic\', \'magazine\'),
\'tax_query\' => array(
array(
\'taxonomy\' => \'Genres\',
\'terms\' => array( \'hot\', \'home\' ),
),
\'posts_per_page\' => 10
);