WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Display ALL Thumbnails from Custom Post Types to Page template

[Resolved] Display ALL Thumbnails from Custom Post Types to Page template

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • <?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; ?>

    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]

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

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

    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>

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Display ALL Thumbnails from Custom Post Types to Page template’ is closed to new replies.