【发布时间】:2017-10-05 18:30:57
【问题描述】:
我试图在位于我的 WP 主题文件夹内的 PHP 文件中调用自定义 AJAX 函数,但是我无法让它检索输出。我认为问题在于将 WP 查询链接到主 WP 文件?
$.ajax({
url: "../../ajax-crew.php",
type: "POST",
data: {loadcrew: true},
etc etc etc ...
我的自定义 ajax-crew.php 文件位于我的主题文件夹中(当我简单地回显“test”时,我将输出检索到我的页面上,但是当我尝试使用 WP 查询时,它不会创建任何输出:
<?php include '../../../wp-load.php'; ?>
<?php
if (isset($_POST['loadcrew'])){
$args = array(
'post_type' => 'team-members',
'order' => 'rand',
'posts_per_page' => 1
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'featured-400-400', true);
$index = $wp_query->current_post;
echo $thumb_url[0];
endwhile;
endif;
} // end if isset
?>
【问题讨论】:
标签: javascript php ajax wordpress