I have a new question, how can I limit the amount of posts coming out of this query? I only need 7
<?php
$newsposts = new WP_Query('cat=restaurant');
if ( is_front_page()) {
echo '<h3 class="member-review">Latest Restaurants</h3>
<div id="extra">';
if ($newsposts->have_posts()) : while ($newsposts->have_posts()) : $newsposts->the_post();
echo '<div class="reslogo"><img src="'.catch_that_image().'"/></div>';
endwhile; endif;
echo '</div>';
}
?>
I tried to put: ('cat=restaurants'.'limit=7')
but she no work. How did i go wrong? any help would be appreciated
It should be:
Another way to write it (helps readability with larger queries) would be:
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.That’s what works for me (showposts):
I think you have a slight error here, the ‘cat’ paramater only accepts a post ID as an Integer
Source:
WP_Query
Parameters