How to limit the posts

It should be:

$newsposts = new WP_Query('cat=restaurant&posts_per_page=7');

Another way to write it (helps readability with larger queries) would be:

$newsposts = new WP_Query(array(
    'cat' => 'restaurant',
    'posts_per_page' => 7,
));

See WP_Query in Codex for description of available parameters.

PS would be good practice to add wp_reset_postdata() at the end. You are (correctly) not modifying main query, but you do change global $post variable with this loop.

Leave a Comment