Home>Support>Live Preview not working when using shortcode that uses wp_query

Live Preview not working when using shortcode that uses wp_query

Hello,

I noticed the Live Preview editor is not working. I just see the loading bar on the live preview. The option panels are all working.

I noticed if I wait 3-4 minutes, the live editor is working, but the page is being dispayed about a 1000 times (hence why it’s loading so long).

After some trial and error runs, I noticed the issue is with a shortcode that displays a full post. If I don’t use that shortcode, it works fine.

The shortcode itself is very basic, and just uses wp_query to display a post using the specific page ID or category.

I wonder, is there an issue with this shortcode, or with PageBuilder when using this shortcode?

//Display Post using Shortcode
add_shortcode('my_display_post', function($atts) {

$input = shortcode_atts( array(
'cat' => '',
'p' => '',
'class' => '', //example: alignleft
'img_size' => '', //options: thumbnail, medium, large, full
), $atts );

$args = array(
'post_type' => 'post',
'posts_per_page' => '1',
'cat' => $input['cat'],
'p' => $input['p'],
);
// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
$output = '';
while ( $the_query->have_posts() ) {

$the_query->the_post();
$output .= '<h2>' . get_the_title() . '</h2>';
$output .= get_the_post_thumbnail( $post_id, $input['img_size'], array( 'class' => $input['class'] ) );
$output .= apply_filters('the_content', get_the_content());

}

/* Restore original Post Data */
//wp_reset_postdata();
wp_reset_query();

return $output;

} else {
// no posts found
}

});

Edit:

Okay I found the issue. It wasn’t actually the shortcode itself, but a plugin that is used inside of the post.  https://codecanyon.net/item/taqyeem-wordpress-review-plugin/4558799?s_rank=5

It seems there is an issue with the plugin when used with the live editor.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More