I'm trying to display a list of posts by tag within a post. I've cobbled together the following code which I wanted to use in a shortcode, but I'm getting nothing displayed…

$args = array(
'tag' => 'my-tag'
$query = new WP_Query( $args );

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->get_template_part( 'entry-summary' );
get_template_part( 'nav', 'below' );

I've tried using this within the loop using a short code and after the loop to test without success. I'm sure I'm missing something obvious!

  • Doesn't seem to make any difference I'm afraid.
    – Badger
    Jul 15, 2015 at 12:36
  • See the updated answer. And please remember to add wp_reset_postdata(); afterwards Jul 15, 2015 at 12:51

1 Answer 1


Did you try without $query-> in front of get_template_part() ?

  • That just causes the server and the browser to go into some sort of meltdown!
    – Badger
    Jul 15, 2015 at 12:39
  • @Badger check, I have updated the answer to be correct. It should work now Jul 15, 2015 at 12:49
  • I have edited the wrong part out of the answer. The part that is staying should be the correct part. If anyone has an issue with this, feel free to roll back my changes ;-) Jul 15, 2015 at 12:50
  • 1
    Thanks @PieterGoosen for your correction and I'm glad it works now ^^
    – Sovnfield
    Jul 15, 2015 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.