WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display ALL Thumbnails from Custom Post Types to Page template (7 posts)

  1. christopherburton
    Member
    Posted 2 years ago #

    I am trying to get ALL the post_thumbnails (Feature Images only, not attachments) from 2 custom Post Types onto a Page template I created.

    How can I do this?

  2. luckdragon
    Member
    Posted 2 years ago #

    <?php
    $loop = new WP_Query("post_type=<custom_post_type>&post_status=publish");
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    <div><? the_post_thumbnail(); ?></div>
    <? endwhile; ?>
  3. christopherburton
    Member
    Posted 2 years ago #

    Hey, Thanks.

    It doesn't seem to be working. Below is my template code.

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

  4. kevmatic34
    Member
    Posted 2 years ago #

    in the query, replace"<custom_post_type>" with your custom post type

  5. christopherburton
    Member
    Posted 2 years ago #

    Ah-ha! That worked. How would I add multiple custom post types to that, as I have 2. 'lettering' & 'typography'?

  6. christopherburton
    Member
    Posted 2 years ago #

    After searching, I tried the code below and it outputs what I wanted. Thanks again.

    <?php
    $loop = new WP_Query( array( 'post_type' => array('lettering', 'typography')&'post_status=publish'));
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    <div><?php echo the_post_thumbnail(); ?></div>
  7. luckdragon
    Member
    Posted 2 years ago #

    oops, forgot the echo, I'm used to using shorthand,
    <?=the_post_thumbnail()?>

Topic Closed

This topic has been closed to new replies.

About this Topic