How can I display a list of WordPress custom posts? How can I display a list of WordPress custom posts? wordpress wordpress

How can I display a list of WordPress custom posts?


Assuming you set up everything correctly and you want to see the post type on a public template page, try this code into mycustomtemplate.php or the equivalent.

<?php $loop = new WP_Query( array( 'post_type' => 'article', 'posts_per_page' => 10 ) ); ?><?php while ( $loop->have_posts() ) : $loop->the_post(); ?>    <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>    <div class="entry-content">        <?php the_content(); ?>    </div><?php endwhile; ?>

You can customize the loop just like you would blog posts and pages. If you want to get all on one page you'll want to remove the limit of 10 on post_per_page I wouldn't suggest it though. I would say set it to 50 or 100 and still use pages.

Source: Custom post types in WordPress


I have the simplest solution. Just create file archive-{custom post type}.php and then, just do loop content as usual.

If you already set the permalink, just type yourdomain.com/{custom post type}.


You can easily achieve this from the definition of your custom post type, starting with WP 3.1. Just set has_archive to true.

Source: http://codex.wordpress.org/Post_Types#URLs_with_Namespaced_Custom_Post_Types