Support › MB Views › How to load views do_shortcode in ajax situationResolved
I have set my view to Custom
I load my content via ajax using this
$shortcode = '[mb_views id="'.$post->ID.'"]';
//$shortcode = '[mbv id="'.$post->ID.'"]'; // depends on which is correct see pic below
But it only outputs the shortcode
Also the shortcodes differ for views
see pic below
How do I display shortcodes for MB Views via ajax?
Thanks in advance
Thanks for pointing this out, the right shortcode is [mbv id="9865"].
To load the shortcode via ajax, this guide maybe helps you https://wordpress.stackexchange.com/questions/108874/loading-shortcode-with-ajax.
You can also check the correct shortcode with view ID before passing the variable to the shortcode.
$post_id = 9865;
$shortcode = '[mbv id="' . $post_id . '"]';
echo do_shortcode( $shortcode );
I have done some tests and can confirm that the method
Will work on a full page refresh but not if the page is loaded via an ajax method
Also, I have tested this with other shortcodes in my system using the "echo do_shortcode( $shortcode );" method and they load all via ajax as without problem
The shortcode seems does not render in the response of Ajax call, you can try to load the shortcode inside the function wp_localize_script().
wp_localize_script( 'script-handle', 'pluginObject', array(
'mbView' => do_shortcode('[mbv id="9865"]')
For more information, please follow this guide https://wordpress.stackexchange.com/questions/121560/do-shortcode-inside-ajax-callback.