Post Pic

WordPress WP Query Function

WordPress can be used for some really cool stuff outside the traditional role of being a “blog”. Although some of the built in functions of WordPress are not inherently known by everyone.

I have a site that I partnered up with a friend that does movie reviews. The site is FlickChick.TV and we use it to post video reviews and also sections for movie trailers, box office results and other movie news. Since we always want the movie reviews at the front and other stuff on category pages we use some queries and custom page templates depending on the category.

On the front page of the site I use a query in the loop to show 10 posts in the featured category ordered by date. The last part of the query is paged so that when I click on previous posts link the results are paged so I don’t see the same posts on each page. That is an important page of the query and now that you know it will save you some frustration.
<?php $wp_query = new WP_Query();
$wp_query->query('cat=4&showposts=10&orderby=date'.'&paged='.$paged);
?>
<?php if (have_posts()) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Related Posts

Popular Posts


Leave Your Response

* Name, Email, Comment are Required