WordPress.org

Ready to get started?Download WordPress

Forums

How to Show the Excerpts from a Custom Post Type (4 posts)

  1. Chris
    Member
    Posted 2 years ago #

    Hi folks,
    I am starting to play around with Custom Post types and am trying to figure out how to show the excerpts from a Custom Post type. I have a custom post type called testimonials and I am trying to show the excerpt of those on the home page. I cannot figure out how to do it.... any ideas?

    Thanks!

  2. lancer_mallik
    Member
    Posted 2 years ago #

    Now with those custom post types and other “bits of content” that don’t necessarily need to be organized by date/chronologically, what approach you suggest taking for letting the editor/admin of the site SORT their order??

  3. Chris
    Member
    Posted 2 years ago #

    Not really sure what you mean, You mean how could they sort their order? Looks like there is a plugin that lets you do that sort of thing. http://wordpress.org/extend/plugins/post-types-order/

    But that doesn't really answer my question as to how to call the excerpts of a custom post type. Anyone?

  4. Chris
    Member
    Posted 2 years ago #

    Not entirely sure if this is the RIGHT way to do it but I am able to accomplish what I want using the following. So if your custom post type is called "testimonials" and you want to display the excerpt try this:

    <?php
    //get specific post_types, display all published content for each of those types
    $args=array(
    'name' => 'testimonials'
    );
    $output = 'objects'; // names or objects
    $post_types=get_post_types($args,$output);
    if ($post_types) {
    foreach ($post_types as $post_type ) {
    $type = $post_type->name;
    $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php the_excerpt() ?>
    <?php
    endwhile;
    }
    wp_reset_query();
    }
    }

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic