• I need to render a given post into a page using a shortcode. The page shall look exactly as the post (but must be a separate post/page).
    In the shortcode function I was able to retrieve the post using get_post($post_id), but I don’t know how to render the retrieved information.
    How can I display the post with all the elements?
    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Be sure to use the ‘ARRAY_A’ parameter in get_post(). Then the main thing is to change the post_type value in the returned array to ‘page’ and then use wp_insert_post(), passing the modified array as the parameter.

    You also need to use update_post_meta() to specify the page template under the key ‘_wp_page_template’.

    Thread Starter claudio

    (@calberti)

    Thank you for the reply. If I understand correctly, wp_insert_post() will insert a copy of the original post in the DB, but this will be a separate new post.
    What I need is only to render the post in the concerned page without creating a copy. I’m just interested in creating an “alias” and not a real duplicate post.
    thanks!

    Moderator bcworkz

    (@bcworkz)

    In order for it to be a true page, an entry must be added to the DB. A particular DB entry can only be a post or a page, not both. The distinction is minor. Depending on the theme, the difference between viewing a single page and a single post could be indistinguishable. With a custom page template though, it would be possible to display post content on a page that shows up in the page table, if that’s any help.

    If you could better explain what you’re actually trying to achieve, I may be able to offer an alternate idea or two. As it stands, I don’t really see the point.

    BTW, even though my first post did not answer your question, for the record, I neglected to mention one needs to also unset the ID key so that a new ID is assigned, otherwise the effect will be to convert a post to a page semi-permanently.

    Thread Starter claudio

    (@calberti)

    OK I see what you mean, I try to better explain what I’m trying to achieve.
    I have a post that is automatically created by a plugin. For simplicity let’s say it’s a product of an e-commerce site.
    Now I want to embed the product description into a page where the theme elements are in another language. The plugin+theme do not work well with most ML plugins. I found one which works OK but needs to associate the translated post to the original one. I.e. I have to provide the post ID of the english version when I create the french version.
    If I create 2 independent posts these will be 2 separate products for the e-commerce plugin, while I need to have a single product with 2 translations.
    Now, I have 1 post which is the english version of the product; then I have a page (or post) where I’m trying to copy the entire english version of the product without creating a new product with the e-commerce plugin. In this way I will still show the english description of the product but within a french theme.
    I understand it may look complicated, I’ll try anyway your suggestion.
    thanks!

    Moderator bcworkz

    (@bcworkz)

    To directly answer your question (I hope), you need some sort of template that pulls in the English product content. This may be as simple as using get_post() and echoing out the content. The template can be for a page or post type that contains the French content.

    I’m afraid I still don’t quite get the concept. If I’ve answered your question, no need to explain further, but I’d like to give you the best solution, which is difficult if I don’t understand where you’re going with this. Your patience is appreciated.

    If the French portion is static boilerplate that is the same for all products, it can be part of the single post template. A post/product request will show the French portion from the template and the English product description from the DB.

    If the French portion is variable, I don’t see how you can avoid having two IDs, one for the French content and one for the English product description. And somehow, the two need to be related to each other in some manner. The only alternative would be to have both languages in one post, possibly divided by some tag in content, or perhaps one language in a custom field.

    One way to deal with the need for two IDs but only one product ID would be for the French content to be a custom post type, whose template pulls in the product description post. Thus all product queries are unaffected by the presence of French content.

    Maybe that’s enough to go on, but if not, tell me what approach would work for you and I can elaborate.

    (You probably saw the spam post that is now deleted. I added a ‘modlook’ tag and it was deleted in the time it took me to type this reply 🙂 Freakin’ spammers have no respect.)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘How to copy post into page’ is closed to new replies.