Reputation: 2964
How do I combine these two fields (category name and posts per page) into one line of code?
<?php $query = new WP_Query( array( 'category_name' => 'investor-news' ) );?>
<?php $query = new WP_Query( array( 'posts_per_page' => 5 ) );?>
Upvotes: 1
Views: 193
Reputation: 90
Alternatively, you can use something like this:
query_posts(array('category_name' => 'investor-news', 'posts_per_page' => 5));
while(have_posts()) : the_post();
//display post code here
endwhile; wp_reset_query();
Upvotes: 0
Reputation: 72299
Based on Manual:-https://codex.wordpress.org/Class_Reference/WP_Query
You can do it like below:-
$args = array(
'category_name' => 'investor-news',
'posts_per_page' => 5
);
$query = new WP_Query( $args );
Upvotes: 2