Php 无法从ajax调用获取post数据-wordpress
我有一个Ajax调用,将更多帖子加载到页面上。一切正常,我从我拥有的模板中得到了HTML,但是它缺少所有的帖子信息,所以它只是HTML框架 我使用相同的模板将第一篇文章加载到页面上,但是当使用ajax调用时,我无法让Wordpress方法显示回数据 当我在模板php文件上进行var转储时,我可以看到所有post信息,但它不会返回到内联php 装载立柱:Php 无法从ajax调用获取post数据-wordpress,php,ajax,wordpress,Php,Ajax,Wordpress,我有一个Ajax调用,将更多帖子加载到页面上。一切正常,我从我拥有的模板中得到了HTML,但是它缺少所有的帖子信息,所以它只是HTML框架 我使用相同的模板将第一篇文章加载到页面上,但是当使用ajax调用时,我无法让Wordpress方法显示回数据 当我在模板php文件上进行var转储时,我可以看到所有post信息,但它不会返回到内联php 装载立柱: foreach (load_posts($offset) as $post) { include(locate_template('_i
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>
我在圈外还是怎么了?我想保持模板现在的状态。同样,post数据在那里,但它不会通过\u permalink()或\u字段(“媒体图像”)以及类似的内容显示…您必须在ajax调用中传递ID。。。你需要哪个职位 将模板文件更改为
<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',$post_ID) ?>" alt="<?php the_field('media_image',$postID) ?>" />
</a>
</div>
<div class="feature__hd">
<h2 class="hdg hdg--lg">
<a href="<?php the_permalink($postID); ?>"><?php the_title(); ?></a>
</h2>
</div>
<div class="feature__bd">
<?php the_excerpt($postID); ?>
</div>
</div>
</div>
</div>
</li>
Ack!为什么不使用get\u template\u part
?还有,你在做AJAX吗?最后,load\u posts
有什么收获吗?这不是一个WP函数(我知道),所以我强烈怀疑你在WordPress结构之外做的事情。