Recently I came across a sitution whereby I wanted to call a list of Wordpress posts from inside the body of another post, i.e., not coding it into a template, but embedding into the body of the post itself.
Not a big drama, I thought to myself: I already have the exec-php plugin installed to enable the execution of PHP from within Wordpress posts, so all I needed to do was call the Wordpress loop from the point inside the post where I wanted my list of links to appear, e.g.:
The code above follows a similar format to that as described in the Wordpress Codex for working with multiple loops.
This worked fine for outputting the title of the post and its permalink. The problem was that I then wanted to the replace the permalink to a link to an external site that was attached to the posts using a custom field.
Unfortunately, this wouldn’t work; no link was output. But after some help from people on the WordPress Support forum, I found that using
get_posts instead of
WP_Query did the trick:
Problem solved! 😊