Sunday, June 6, 2010

Wordpress 3.0: Query custom post types

April 22, 2010 by admin · Leave a Comment 

In Wordpress 3.0 you can create custom types of post.

Good news for developers, there’s nothing hard or new in the process. Custom post types can be retrieved easily, using the WP_Query object.
The following example will create a custom loop which will get only the albums custom post type.

<pre><ul>

<?php global $wp_query;
$wp_query = new WP_Query("post_type=albums&post_status=publish");

while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul></pre>
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • Netvibes
  • Reddit
  • RSS
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Twitthis
  • Blogosphere News
  • email
  • LinkedIn
  • Linkter
  • Live
  • MyShare
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
  • Yahoo! Bookmarks
  • Yahoo! Buzz

Related posts:

  1. show most commented pages with images in Wordpress
  2. Custom post types with custom taxonomies
  3. How to create a custom post type in Wordpress 3.0
  4. add an expiration date to your article
  5. Wordpress 3.0:Add custom backgrounds

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

SEO Powered by Platinum SEO from Techblissonline