无法从ajax调用获取发布数据 - wordpress

时间:2016-01-12 21:13:00

标签: php ajax wordpress

我有一个Ajax调用将更多帖子加载到页面上。一切正常,我从我拥有的模板中取回HTML,但它缺少所有帖子信息,所以它只是html骨架。

我使用相同的模板将第一篇帖子加载到页面上,但是当使用ajax调用时,我无法使用Wordpress方法显示数据。

当我在我的模板php文件上进行var转储时,我可以看到所有的帖子信息,但它没有回到内联php。

加载帖子:

foreach (load_posts($offset) as $post) {
    include(locate_template('_includes/loop-archive-single.php'));
} 

模板:

<li>
    <div class="card">
        <div class="card__bd">
            <div class="feature">
                <div class="feature__media">
                    <a class="imgLink" href="<?php the_permalink(); ?>">
                        <img src="<?php the_field('media_image') ?>" alt="<?php the_field('media_image') ?>" />
                    </a>
                </div>
                <div class="feature__hd">
                    <h2 class="hdg hdg--lg">
                       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </h2>
                </div>
                <div class="feature__bd">
                    <?php the_excerpt(); ?>
                </div>
            </div>
        </div>
    </div>
</li>

我是在循环之外还是在发生什么?我想以现在的方式保留模板。同样,帖子数据在那里,但它不会通过the_permalink()或the_field('media_image')和类似的东西显示......

1 个答案:

答案 0 :(得分:0)

您必须在ajax调用中传递ID ...您需要的帖子

将模板文件更改为

std::string