0

We have a shortcode that causes WP_Query to be executed, retrieving an instance of a custom post type. In our single.php this changes the context (after the call to the_content()) from the original post (with the shortcode in it) to that of the custom post retrieved.

I spotted this because the comments template wasn't displaying, as the comment_status on the custom post is 'closed' - what we're interested in, however, is that the comment_status on the original post is 'open'.

Is this an error in the execution of our shortcode/custom post type, is there a way of doing this that won't mess up what happens in single.php?

Thanks,

Toby

1 Answer 1

1

You need to call wp_reset_postdata() after a secondary query to restore the global $post to its original context.

0

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.