Php WP-Ajax以非认证模式从post中删除短代码

Php WP-Ajax以非认证模式从post中删除短代码,php,wordpress,wordpress-theming,wordpress-rest-api,Php,Wordpress,Wordpress Theming,Wordpress Rest Api,我有一个自定义wordpress主题的奇怪问题 我在我的主题中启用了AJAX操作,如下所示: add_action('wp_ajax_get_levelOne_Content', 'get_levelOne_Content'); add_action('wp_ajax_nopriv_get_levelOne_Content', 'get_levelOne_Content'); get\u levelOneContent不会做任何花哨的事情。相反,它只是获取post内容并返回HTML输出作为AJ

我有一个自定义wordpress主题的奇怪问题

我在我的主题中启用了AJAX操作,如下所示:

add_action('wp_ajax_get_levelOne_Content', 'get_levelOne_Content');
add_action('wp_ajax_nopriv_get_levelOne_Content', 'get_levelOne_Content');
get\u levelOneContent
不会做任何花哨的事情。相反,它只是获取post内容并返回HTML输出作为AJAX的负载

function get_levelOne_Content()
{   
    $postid = $_POST["postid"];
    
    require(get_template_directory() .'/../../../wp-load.php');
    @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
    @header('X-Robots-Tag: noindex');
    send_nosniff_header();
    nocache_headers();
    
    $post_content = get_post($postid);
    print_r($post_content);
    $content = $post_content->post_content;
    $title = $post_content->post_title;
    $currentLang = apply_filters('wpml_current_language', null);    
    ?>
<div class="wrapper__content fw fx fx__row">
    <div class="post__content fx fx__col p__4">

        <h2 class="txt0-t"><?php echo $title; ?></h2>
        <div class="m__t-2">
            <?php echo apply_filters('the_content', $content);?>
        </div>
    </div>
</div>
<?php
exit();
} ?>
函数get\u levelOne\u Content()
{   
$postid=$_POST[“postid”];
require(get_template_directory()。/../../../../wp load.php');
@标题('Content-Type:text/html;charset='。获取选项('blog\u charset');
@标题('X-Robots-Tag:noindex');
发送_nosniff_头();
nocache_头();
$post\u content=get\u post($posted);
打印(发布内容);
$content=$post\u content->post\u content;
$title=$post\u content->post\u title;
$currentLang=apply_filters('wpml_current_language',null);
?>
我感兴趣的帖子有一个WP-Form-shortcode标签。这段代码工作得非常好,当我以用户身份登录这个站点时,它就像我的预期一样。 但是,作为未经身份验证的用户,通过get_post()方法,短代码不会出现在有效负载中。我用
print\r($post_content);
验证了这一点,它没有显示与原始帖子中存在的短代码相关的任何内容

我已经使用了我已知的技能来解决这个问题,但我无法做到。在这里发布之前,我已经在互联网上搜索并尝试了各种解决方案,但建议的解决方案都不起作用

谁能给我提点建议吗


谢谢。

除了WP Form,您还尝试过其他短代码吗?您好!是的,我刚刚尝试了嵌入标记,它按预期工作。因此,问题在于WPForms配置?是的,因为您已经使用了正确的挂钩(一个用于登录,另一个用于未登录)。可能您的WP表单已配置为仅为登录用户显示。您可以尝试使用
联系表单7
强大表单
创建相同的表单。感谢链接。我之前也尝试过此操作。我还启用了其他加载项,并使用了一些设置。在我看来,我无法嵌入表单的短代码并以匿名方式查看。因此,问题与WP Rest API完全无关。相反,罪魁祸首是整个WPForms。我现在尝试几件事,稍后再发回。感谢您的输入。祝您好运!