Wordpress无法从自定义帖子中查找数据

时间:2016-12-07 08:27:53

标签: php wordpress

我对Wordpress很陌生,所以如果这很简单,你就不得不原谅我!

我已经接管了一个Wordpress网站,其中一个从自定义帖子获取内容的组件已经停止工作。这是因为托管已被更改。有一个php文件(下面),不能再获取数据了。

任何想法为什么?

的script.js

        $.ajax({
            url: BASE_DIR + '/events.php',
            dataType: 'json',
            success: function(response) {
                ajaxResponse = response;
                init(ajaxResponse);
            }    
        });

events.php

<?php

header("Content-Type: application/json");

$parse_uri = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
require_once($parse_uri[0] . 'wp-load.php');

$response = array();

$args = array(
    'posts_per_page' => -1,
    'post_type' => 'event',
    'meta_key' => 'recurring_event',
    'meta_value' => '1'
);

$events = get_posts($args);

foreach ($events as $event) {

    $eventObj = array();

    $eventObj['id'] = $event->ID;
    $eventObj['title'] = $event->post_title;
    if (get_field('start_time', $event->ID)) {
        $eventObj['start'] = get_field('start_time', $event->ID);
    } else {
        $eventObj['start'] = '00:00';
    }
    $eventObj['day'] = get_field('days', $event->ID);
    $eventObj['url'] = get_the_permalink($event->ID);
    $eventObj['allDay'] = get_field('all_day_event', $event->ID);
    $eventObj['isMeeting'] = get_field('meeting_event', $event->ID);

    $response[] = $eventObj;

}

echo json_encode($response);

?>

我希望这是足够的信息,如果不是大声喊叫的话!

1 个答案:

答案 0 :(得分:0)

似乎此代码不完整。 显然也用于AJAX。 可以在此链接上观看如何在Wordpress中使用AJAX

I am trying to submit a form through ajax in wordpress, but the result in the success callback gives me the page's markup in string