[wp-hackers] Proper method for creating custom query inside shortcode

Claude Needham gxxaxx at gmail.com
Wed Aug 10 17:37:44 UTC 2011

Problem solved.

Turns out I was vastly under-estimating the subtly of wordpress.

The nested loops section
(http://codex.wordpress.org/The_Loop#Nested_Loops) gave me the clue.

I did not realize that the_content etc would access the data for the
$my_query object. I was stupidly trying to craft some means of doing
the_content with $my_query directly. (A bit of not so useful example
code from a google search put me in the wrong direction. I think I'll
keep site:wordpress.org in my google searches from now on.)

When I stopped fiddling with all the dials it settled down and worked
like a charm.

Very impressive behind the scenes magic going on in wp.

Special thanks to codex contributors for including that "nested loops" bit.

Claude Needham

On Tue, Aug 9, 2011 at 11:50 PM, Claude Needham <gxxaxx at gmail.com> wrote:
> I would like to embed an archive of the five most recent posts for a
> particular category in the main content of a page.
> I have managed to do this with some success by editing the page template.
> However, it would be better to do this via a shortcode -- so that page
> content can appear before and after the archive.
> I've done this wrong in two different way.
> When I managed to create an infinite loop, I decided it was time to
> see if there is example code or at least a clue about the proper
> method
> for implementing a custom query within the main content of a page.
> Any pointers would be appreciated.
> Regards,
> Claude Needham

More information about the wp-hackers mailing list