WordPress.org

Forums

[resolved] Custom Post Type list posts (3 posts)

  1. WatsonN
    Member
    Posted 1 year ago #

    I know there is a way but I have not been able to get it right, yet.
    I have four custom post types and I want to put each one into a list of all their post titles. I know I need the_title() and the_permalink() But how do I specify which post type to pull from?

  2. jomsky
    Member
    Posted 1 year ago #

    If you are using WP_Query you could use the post_type parameter:

    $query = new WP_Query( array( 'post_type' => array( 'post', 'page', 'movie', 'book' ) ) );

    Or for a single post type:

    $query = new WP_Query( array( 'post_type' => 'book' ) );

  3. WatsonN
    Member
    Posted 1 year ago #

    Thank you, that was exactly what I needed!

    $query = new WP_Query( array( 'post_type' => array( 'labs', 'activities', 'projects', 'testreview' ) ) );
    
    while ( $query->have_posts() ) : $query->the_post();
    	echo '<li><a href="';
    	the_permalink();
    	echo '">';
    	the_title();
    	echo '</a></li>';
    endwhile;

Topic Closed

This topic has been closed to new replies.

About this Topic