admin管理员组

文章数量:1122832

I am trying to load my custom post type events into jquery plugin full calendar but nothing is working. I have made a php file with this code

include "wp-load.php";
global $wpdb;
header('Content-Type:application/json');
$events = array();
$result = new WP_Query('post_type=events&posts_per_page=-1');
foreach($result->posts as $post) {
$events[] = array(
'title'   => $post->post_title,
'start'   => '2018-03-12T20:00:00',

);
}
echo json_encode($events);
exit;

But its not loading anything

I am trying to load my custom post type events into jquery plugin full calendar but nothing is working. I have made a php file with this code

include "wp-load.php";
global $wpdb;
header('Content-Type:application/json');
$events = array();
$result = new WP_Query('post_type=events&posts_per_page=-1');
foreach($result->posts as $post) {
$events[] = array(
'title'   => $post->post_title,
'start'   => '2018-03-12T20:00:00',

);
}
echo json_encode($events);
exit;

But its not loading anything

Share Improve this question edited May 26, 2018 at 21:10 fuxia 107k38 gold badges255 silver badges459 bronze badges asked May 26, 2018 at 20:38 RafRaf 11 bronze badge 1
  • This is not the correct way to load WordPress. You should move that code to a plugin, or a child theme. Also, I would replace the include statement by a require, so that the script breaks if it cannot find the file wp-load.php And finally, you could add these two lines after the require: ini_set('display_errors', 1); and ini_set('error_reporting', E_ALL);. – Mike Commented May 27, 2018 at 14:50
Add a comment  | 

1 Answer 1

Reset to default 0

Have reviewed your code but could not get what actually is wrong with the code.

Another possible solution is that, you can use third-party WordPress plugin WP Full Calendar and select your post type in the plugin settings. You can then use short-code to display the full calendar in any of your website page/post.

WP FullCalendar: https://wordpress.org/plugins/wp-fullcalendar/

本文标签: custom post typesload wordpress events into full calendar jquery