0

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->the_post();
        $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!

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

1 Answer 1

1

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

4
  • That just causes the server and the browser to go into some sort of meltdown!
    – Badger
    Commented Jul 15, 2015 at 12:39
  • @Badger check, I have updated the answer to be correct. It should work now Commented 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 ;-) Commented Jul 15, 2015 at 12:50
  • 1
    Thanks @PieterGoosen for your correction and I'm glad it works now ^^
    – Sovnfield
    Commented Jul 15, 2015 at 12:57

Your Answer

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

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