• Resolved robdxw

    (@robdxw)


    Hi

    I’m encountering an issue where, when running a template test, the incorrect post content can be displayed on posts that should not be part of the test.

    e.g. If I set up a template test aimed exclusively at a custom post type, content on standard pages is rendered incorrectly, usually meaning that posts render content from a different post completely when viewed in the front end.

    This does not happen on all themes, but it is consistently happening in some.

    I’ve narrowed the issue down to the logic in the includes/hooks/experiments/templates/preview.php file, specifically around line 50:

    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
    $query->the_post();
    $links[ $key ] = get_permalink();
    wp_reset_postdata();
    }

    It seems this is somehow interfering with the default query (despite the call to wp_reset_postdata()) which results in the template’s call to the_content() referencing the wrong post. It appears that the_content() is rendering content from the post that this query returns, rather than the post that is being viewed.

    The correct behaviour happens if I either comment out those lines, or replace them with the get_posts() equivalent:

    $posts = get_posts($args);
    if (!empty($posts)) {
    $links[$key] = get_permalink($posts[0]);
    }

    Sorry I can’t offer full steps on how to recreate (the themes where I’m experiencing this are not ones I can share), but if it’d be possible to look into this (and possibly even fix by using the get_posts() code I shared above), that’d be great, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Aguilera

    (@davilera)

    Sure thing. The change you’re proposing should not interfere with anything else so… I’ll be happy to include it in our next release. In the meantime, please manually apply it to your site by tweaking our plugin (I believe you already have?).

    Thread Starter robdxw

    (@robdxw)

    Thanks, much appreciated!

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

The topic ‘Template tests can result in incorrect post content being rendered’ is closed to new replies.