jcadima
3/8/2015 - 10:32 PM

Query custom post type, get image source and title

Query custom post type, get image source and title

<div class="row">
<?php 
    $args = array ( 'post_type' => 'portfolio');
    $portfolioquery = new WP_Query ($args);
 ?>

<?php  if( have_posts() ) : while($portfolioquery->have_posts() ) : $portfolioquery->the_post(); ?>

   <div class="col-md-3 col-xs-4 portfolio-piece">
      <?php 
      // get the url id
        $thumbnail_id = get_post_thumbnail_id( );
        // get actual url
        $thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true );
       ?>
      <p><a href="<?php the_permalink(); ?>"><img src="<?php echo $thumbnail_url[0]; ?>"></a></p>
        <h4><a href="<?php the_permalink(); ?>"><?php the_title() ; ?></a></h4>
   </div>

</div>

<?php endwhile; endif; ?>