So, I have a following ajax setup:
PHP: menu.php
<!--Menu-->
<div class="rh_menu">
<a href="#rhp_front_rhp_id" class="is-active" id="rhp_id">Front</a>
<a href="#rhp_front_ca_other_id" id="ca_other_id">Other</a>
</div>
<!--Content Div-->
<div class="rhp_hide">
<div class="rrp_container is-active" id="rhp_front_rhp_id">
<div class="spinner is-active"></div>
</div>
<div class="rrp_container" style="display:none;" id="rhp_front_ca_other_id">
<div class="spinner"></div>
</div>
</div>
01_house_rhp_id.php <-- First button which is called by the Ajax
<div class="my_shortcode">
<?php echo do_shortcode('[some_shortcode]'); ?>
</div>
Function.php
// load the javascript
wp_enqueue_script( 'ajax-script', '/03.includes/js/rh_ajax.js', array('jquery') );
wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
//Ajax call for House front page
function my_tab_callback() {
$template_part_path = 'page-parts/01_house_' . $_GET['id'];
get_template_part($template_part_path);
exit;
}
add_action('wp_ajax_my_tab', 'my_tab_callback');
add_action('wp_ajax_nopriv_my_tab', 'my_tab_callback');
rh_ajax.js
//To hide other divs
jQuery('.rh_menu a').click(function() {
var rh_id = jQuery(this).attr('id');
jQuery('[id^="rhp_front_"]').hide();
jQuery('#rhp_front_' + rh_id).show();
});
//To initiate first click
jQuery(window).load(function() {
jQuery("#rhp_id" ).trigger( 'click' );
return false;
});
//Ajax call
jQuery(document).ready(function() {
jQuery('.rh_menu a').click(function(e) {
e.preventDefault();
var tab_house_id = jQuery(this).attr('id');
jQuery.ajax({
type: "GET",
url: ajax_object.ajax_url,
dataType: 'html',
data: ({ action: 'my_tab', id: tab_house_id}),
success: function(data){
jQuery('#rhp_front_' + tab_house_id).html(data);
console.log(data);
},
error: function(data)
{
alert("Nope");
console.log(data);
return false;
}
});
});
});
So, it looks like when a shortcode is parsed by ajax, it is not recognized and gave me 500 server error.
How can I modify above setting so that I can use the shortcode within ajax setting?
Thanks!