我会通过ajax加载页面的内容,里面有我的一个表单通过CF7插件生成的短码。当呈现内容时,不会处理短码并将其打印为文本。有没有办法在ajax调用中强制执行短代码?谢谢你M。
这是js脚本:
function getcontent(postid){
// here is where the request will happen
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',//ajax controller request
data:{
'action':'dch',//action invoked
'fn':'ghcontent',//function required
'postid':postid//if of post required
},
cache: false,
async:true,
timeout: 3000,
success:function(data){
jQuery("#posthome").html(data);//print the html (content)
},
error: function(errorThrown){
console.log(errorThrown);
}
});
}这是我的php代码:
add_action('wp_ajax_nopriv_dch', 'ghcontent');
add_action('wp_ajax_dch', 'ghcontent');
function ghcontent(){
$args = array('page_id' => $_REQUEST['postid']);
query_posts($args);
if(have_posts()) :
while (have_posts()) : the_post();
the_content();
endwhile;
endif;
die();
}发布于 2015-01-13 01:30:21
do_shortcode在您的admin-ajax.php中不起作用,请尝试生成您自己的ajax操作。检查类似问题的以下答案:https://wordpress.stackexchange.com/questions/53309/why-might-a-plugins-do-shortcode-not-work-in-an-ajax-request
发布于 2013-05-12 02:02:59
当the_content筛选器运行时,将应用快捷代码:
$post = get_post( $_REQUEST['postid'] );
$return = apply_filters( 'the_content', $post->post_content );
echo $return;
die();https://stackoverflow.com/questions/16500088
复制相似问题