PHP查询:在数组中添加多个字段?

时间:2017-01-27 04:51:28

标签: php wordpress

如何将这两个字段(类别名称和每页的帖子)合并为一行代码?

<?php $query = new WP_Query( array( 'category_name' => 'investor-news' ) );?>
<?php $query = new WP_Query( array( 'posts_per_page' => 5 ) );?>

2 个答案:

答案 0 :(得分:2)

基于手册: - https://codex.wordpress.org/Class_Reference/WP_Query

你可以这样做: -

$args = array(
    'category_name' => 'investor-news',
    'posts_per_page' =>  5
);
$query = new WP_Query( $args );

答案 1 :(得分:0)

或者,您可以使用以下内容:

query_posts(array('category_name' => 'investor-news', 'posts_per_page' => 5));

while(have_posts()) : the_post();
    //display post code here
endwhile; wp_reset_query();