Ive seen similar questions on here but I am already using WP_Query and wp_reset_postdata.
In short I wrote a shortcode that queries our Custom Post Type to display posts specific to a category. Everything works except the shortcode is only displaying one post when I know there is more.
I know it is something super simple I missed :)
The Query:
function get_gallery_query( $category ){
$gallery_query = new WP_Query(
array(
'post_type'=>'custom_gallery',
'posts_per_page'=> '100',
'tax_query' => array(
array(
'taxonomy' => 'gallery_category',
'field' => 'slug',
'terms' => $category
)
)
)
);
if ( $gallery_query->have_posts() ) :
//the loop
while($gallery_query->have_posts() ) : $gallery_query->the_post();
$output = '<article class="masonry-entry" id="post-' . get_the_ID() .'" ' . get_post_class() .' >
<div class="masonry-thumbnail border">
<a href="' . get_post_permalink() . '" title="' . get_the_title() . '" class="inner-shadow">' . get_the_post_thumbnail(get_the_ID(), 'masonry-thumb') .'</a>
</div><!--.masonry-thumbnail-->
<div class="masonry-details">
<h5><a href="' . get_post_permalink() . '" title="' . get_the_title() . '"><span class="masonry-post-title"> ' . get_the_title() .'</span></a></h5>
<div class="masonry-post-excerpt">
' . getPostLikeLink(get_the_ID()) .' <p class="post-comment"><a href="' .get_post_permalink() . '"><i class="fa fa-comments qcomment" title="Comments"></i></a> ' . comments_number( ' ', '<sup>1</sup>', '<sup>%</sup>' ) . '</p>' . getBookmarkLink(get_the_ID()) . '
</div><!--.masonry-post-excerpt-->
</div><!--/.masonry-entry-details -->
</article><!--/.masonry-entry-->';
endwhile;
wp_reset_postdata();
else :
$output = 'Sorry, but there are no galleries matching your request';
endif;
return $output;
}
$output
, you need to concatenate the previous value with the new value.'posts_per_page'=> '100',
to'posts_per_page'=> 100,
- so that it's passing a number instead of a string, though I'm not sure it matters.