With a WP_Query()
you can have all of them what you want in an easy way. See all the arguments available in the Codex. With the following code, we are grabbing all(-1
) the posts from wp_posts
table, and using the post ID we are grabbing the postmeta items.
<?php
$productquery = new WP_Query( array( 'post_type'=>'wpcproduct','post_status'=>'publish','posts_per_page'=>-1 ) );
if( $productquery->have_posts() ) :
while( $productquery->have_posts() ) : $productquery->the_post();
global $post;
$post_id = $post->ID;
echo '<h2>'. $post_id .' - '. get_the_title() .'</h2>';
echo '<img src="'. get_post_meta( $post_id, 'product_img1', TRUE ) . '" alt="Product Image 1">';
echo '<img src="'. get_post_meta( $post_id, 'product_img2', TRUE ) . '" alt="Product Image 2">';
echo '<img src="'. get_post_meta( $post_id, 'product_img3', TRUE ) . '" alt="Product Image 3">';
endwhile;
else :
echo __( 'No Product\'s found', 'textdomain' );
endif;
wp_reset_postdata(); //reset the query after use