I’ve seen this question come up quite a few times:
How do I put a post into another post?
How do I include a post inside a page?
I always thought it was a really rookie question by people who didn’t understand WordPress and how it works. And I suppose that may still be true to a certain extent, but a couple of occasions have lent themselves to using this for legitimate needs.
For example, for one of my clients, they wanted to return their equivalent product if a user searched for a competitor’s product on their site. They wanted to return the usual product information, but wanted information at the top of the page explaining that the product shown below is the equivalent product for what they searched for and to look for the specific product number in the product literature. So below that, it was necessary to paste the entire product information post which already exists. So this was a good reason to use this ability.
In short, what this snippet does is create a shortcode (include_post) in the last line, which has a single argument; the post ID (id, from line 2). The shortcode uses that post ID to find the appropriate post content and then returns that content in place of the shortcode.
The syntax for using the shortcode with the snippet above would be:
If you’re not sure how to get the post ID, go to your list of posts. When you edit one, the URL will include the post ID. In this example, the URL would look like this:
(Alternatively, you could add a column to your posts editor which shows the post ID next to each post.)
You could also use this functionality to create snippets of text that you use repeatedly and paste them into posts, or to paste common suggestions or disclaimers into posts, by creating posts specifically for those pieces of text and then using the shortcode to pull them into any other post. What have you used this for? I’m always interested to hear how you use these snippets.