请遵循正确的wordpress方法,不要遵循任何人的代码或复制粘贴代码。
/*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-
includes/query.php
*/
$args = array(
//////Category Parameters - Show posts associated with certain categories.
//http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
//all categories parameter
\'cat\' => 5,//(int) - use category id.
\'category_name\' => \'staff, news\', //(string) - Display posts that
have these categories, using category slug.
\'category_name\' => \'staff+news\', //(string) - Display posts that
have "all" of these categories, using category slug.
\'category__and\' => array( 2, 6 ), //(array) - use category id.
\'category__in\' => array( 2, 6 ), //(array) - use category id.
\'category__not_in\' => array( 2, 6 ), //(array) - use category id.
\'post_type\' => \'post\', //post or you can use your custom post type
\'post_status\' => \'publish\',
\'order\' => \'DESC\',
\'orderby\' => \'date\');
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
// Do Stuff
} // end while
} // endif
// Reset Post Data
wp_reset_postdata();