Shortcode WP_Query Object Hijacks Main Loop???
-
I’m experiencing some unexpected behavior. I have a page template that after the_content() puts in an “Edit This…” link via edit_post_link().
One the News page, I’m using a custom shortcode that lists all of the posts from the News category (I’m keeping it as a page rather than a category to keep it in the page navigation structure).
The shortcode uses it’s own $posts variable which is a new instance of WP_Query. It’s a straightforward loop that builds HTML output for listing the posts.
What’s weird is that the edit_post_link() in the page template is actually picking up the edit link from the last post in the shortcode loop. I was under the impression that new WP_Query objects wouldn’t mess with the main loop (hence the design pattern).
Any ideas why this is happening?
Thanks!
-Nate
- The topic ‘Shortcode WP_Query Object Hijacks Main Loop???’ is closed to new replies.