WordPress.org

Ready to get started?Download WordPress

Forums

Shortcodes in posts that are displayed in page templates (3 posts)

  1. polaris1
    Member
    Posted 2 years ago #

    I friend who has a large number of sales landing pages, each with a unique intro and a shared main content body. I've made the management of these easier by creating a bunch of templates as follows: Each template pulls in a unique post for the introduction, and then pulls in another common post for the main body. This works great, except when it comes to running plugin shortcodes in either of the posts that are queried and displayed in a template. The shortcodes work when viewing the actual post, but when you view the page that uses the template that queries and displays this post, the shortcodes fail.

    Specifically, I need to make it so he can use shortcodes to embed a video using a video player plugin.

    I was thinking of adding a plugin to allow PHP in posts/pages and then instructing my friend to wrap each shortcode in do_shortcode().

    This just seems messy. Are there any other ways of doing this? Thanks for any advice.

  2. polaris1
    Member
    Posted 2 years ago #

    Here is the solution:

    Instead of querying posts like this:

    <?php
    $post_id = 13;
    $queried_post = get_post($post_id);
    echo $queried_post->post_content;
    				?>

    Do it like this:

    `<?php
    $query = new WP_Query('p=13');
    if($query->have_posts())while($query->have_posts()):
    $query->the_post();
    ?>
    <?php the_content();?>
    <?php endwhile; ?>`

  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    in the 'get_post()' code, you could also possibly try:

    echo apply_filters('the_content', $queried_post->post_content);

Topic Closed

This topic has been closed to new replies.

About this Topic