尽管在网站上显示内容,WP 短代码仍返回 JSON 错误

问题描述 投票:0回答:1

我创建了一个自定义短代码来显示特定的 CPT 循环。代码如下:

function bundle_grid_shortcode() {
    $args = array(
        'post_type'      => 'bundle',
        'posts_per_page' => -1,
        'orderby'        => 'title',
        'order'          => 'ASC',
    );
    
    $query = new WP_Query( $args );

    echo '<div class="container">';
    echo '<div class="row text-center justify-content-center">';
    if ( $query->have_posts() ) {

        while ( $query->have_posts() ) {
            $query->the_post();
    
            $steam = get_field('steam');
            $nx = get_field('nintendo');
            $t1 = get_field('title1');
            $t2 = get_field('title2');
            $percentage = get_field('percentage');
            $setdate = get_field('date');
    
            ?>
            <div class="col-lg-4 col-xs-12">
                <div id="post-<?php the_ID(); ?>" class="card card-bundle">
                    
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                        <?php 
                        if ( has_post_thumbnail() ) {
                            the_post_thumbnail();
                        }
                        else {
                            echo '<img src="https://picsum.photos/seed/picsum/1920/1080" class="img-responsive img-fluid card-img-top" alt="dummy img" />';
                        }
                        ?>
                    </a>

                    <div class="card-body">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                        <?php 
                            the_title(); 
                        ?>
                    </a>
                    
                    </div>
                </div>
            </div>
            <?php
        }
    }
    echo '</div></div>';

    wp_reset_postdata(); 
}

add_shortcode('bundle-grid', 'bundle_grid_shortcode');

尴尬的是,总体来说它显示的是我想要的东西。但我根本无法通过编辑器/古腾堡更新此页面内容,因为它下降了:

更新失败。该响应不是有效的 JSON 响应。

这是为什么呢?我不明白。

php wordpress shortcode
1个回答
0
投票

调试更新帖子并收到“更新失败。响应不是有效的 JSON 响应”时发生的情况。您最好的选择是查看浏览器的开发人员工具中的实际响应。

此页面解释了如何执行此操作:https://balsamiq.com/support/faqs/browserconsole/

打开工具后,转到网络选项卡。然后点击您要更新的帖子的“更新”。您将看到正在提出新请求。

请求网址将如下所示:https://example.com/wp-json/wp/v2/posts/741861?_locale=user

现在,当您单击请求时,您将看到一些额外的选项卡。看这个图片:

© www.soinside.com 2019 - 2024. All rights reserved.