logo

$5
Query Custom Post

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?

Kirk O'Connor | 07/28/10 at 8:50pm | Edit


(2) Possible Answers Submitted...

  • avatar
    Last edited:
    07/28/10
    11:21pm
    Deepak Thomas says:

    <?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.

    Previous versions of this answer: 07/28/10 at 10:07pm | 07/28/10 at 10:09pm | 07/28/10 at 11:21pm

  • avatar
    Last edited:
    07/30/10
    11:06pm
    Guillermo Sornoza says:

    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(); ?>


This question has expired.





Current status of this question: Completed