I have created a custom post type called Members.
Each Members custom post is associated with a number of categories one of these categories being All Members.
I want to construct a query that displays the title (as a link to the relevant custom post) of the most recent 10 custom posts that have been associated with the All Members category.
Can anyone provide me with the code to do this?
Guillermo Sornoza answers:
Where you want to display the links, put the next code
<?php query_posts('post_type=members&posts_per_page=10&category_name=All Members');
if (have_posts()) { ?>
<ul>
<?php
while (have_posts()) { the_post(); ?>
<li>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?></p></li> <?php
}
?>
</ul> <?php
} ?>
<?php wp_reset_query(); ?>
Deepak Thomas answers:
<?php
/*
Template Name: All Members Page Template
*/
?>
<?php get_header() ?>
...
<?php get_sidebar() ?>
...
<?php global $wp_query;
$page_num = $paged;
if($pagenum='') $pagenum=1;
$wp_query = new WP_Query("showposts=10&post_type=members&cat=32&post_status=publish&paged=".$page_num);
//replace post_type and cat with post_type slug and cat ID respectively.
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="lists" id="post-<?php the_ID(); ?>">
<h2 class="listsh2"><a href="<?php the_permalink(); ?>" title="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="exerpt"><?php the_excerpt(); ?></div>
</div><!-- /post -->
<?php endwhile; ?>
<?php if(function_exists('wp_paginate')) wp_paginate() ?>
...
<?php get_footer() ?>
Make a new Page and select " All Members Page Template " as template.