WP_Query is printing out only one post when posts_per_page is set to multiple

I made my own custom post type and the shortcode to output the custom post type. It all works fine so far, but once I tried adding more posts I still get only one on the page and not more. posts_per_page is set to 3 or more but still nothing.

// Custom Post Type for Use Cases page slider

function create_post_type() {
register_post_type( ‘use_cases’,
array(
‘labels’ => array(
‘name’ => __( ‘Use Cases’ ),
‘singular_name’ => __( ‘Use_Case’ )
),
‘public’ => true,
‘has_archive’ => true,
)
);
}
add_action( ‘init’, ‘create_post_type’ );

// Shortcode for Use Cases caption

add_shortcode(‘Use_Case’, ‘use_case_shortcode_query’);
function use_case_shortcode_query($atts, $content){
echo “working”;
extract(shortcode_atts(array( // a few default values
‘posts_per_page’ => ‘3’,
‘post_type’ => ‘use_cases’,
)
, $atts));

global $post;

$posts = new WP_Query(array( // a few default values
‘posts_per_page’ => ‘3’,
‘post_type’ => ‘use_cases’
));
//print_r($posts);
$output = ”;
if ($posts->have_posts()):
while ($posts->have_posts()):
//echo var_dump($posts->the_post());
$posts->the_post();
$out = ‘<div class=”use_case_boxes”>
<h4>Name: <a href=”‘.get_permalink().'” title=”‘ . get_the_title() . ‘”>’.get_the_title() .'</a></h4>
<p class=”Film_desc”>’.get_the_content().'</p>’;
// add here more…
$out .='</div>’;
/* these arguments will be available from inside $content
get_permalink()
get_the_content()
get_the_category_list(‘, ‘)
get_the_title()
and custom fields
get_post_meta($post->ID, ‘field_name’, true);
*/
endwhile;
else:
return; // no posts found
endif;
wp_reset_query();
return html_entity_decode($out);
}

Read more here:: WP_Query is printing out only one post when posts_per_page is set to multiple

Leave a Reply

Your email address will not be published. Required fields are marked *