关于Wordpress集成的FullCalendar-wpdb和json问题 [英] FullCalendar on Wordpress integration - wpdb and json issue

查看:109
本文介绍了关于Wordpress集成的FullCalendar-wpdb和json问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关在Wordpress中使用全日历的帮助.

I'm looking for help to use fullcalendar in Wordpress.

我正在从phpmyadmin中名为wp_evenement的自定义表中集成计划表

I'm integrating a schedule from a custom table in phpmyadmin called wp_evenement

所以,我有两个文件

一个带有模板页面的模板,其中显示日历,并带有fullcalendar的脚本. 这会调用另一个名为"events.php"的文件,我正在尝试从数据库中获取json结果.

One with template page, where the calendar is displaying and with the script from fullcalendar. This call an other file called 'events.php' where I'm trying to get json result from database.

我尝试使用$ wpdb,但是它不起作用(或者我无法使其起作用). 而且我尝试使用新的PDO连接到数据库,但是仅当以管理员身份连接时它才起作用...

I tried to use $wpdb but it doesn't work (or I can't make it work). And I tried to connect to database with new PDO but it only works when I'm connected as admin...

有人用全局$ wpdb解决方案帮助我吗?

Does someone help me with global $wpdb solution ?

这是我的代码:

模板:

<div id='calendar' style="margin-top:100px;"></div>    
<script>
            var $ = jQuery;
            $(document).ready(function() {
              var date = new Date();
              var d = date.getDate();
              var m = date.getMonth();
              var y = date.getFullYear();


              var calendar = $('#calendar').fullCalendar({
               editable: true,
               header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
               },


               events: "https://www.exemple.org/wp-content/mytheme/fullcalendar/events.php/",


               eventRender: function(event, element, view) {
                if (event.allDay === 'true') {
                 event.allDay = true;
                } else {
                 event.allDay = true;
                }
               }

              });

             });

            </script>

events.php

  <?php


// List of events
 $json = array();

 // Query that retrieves events
 $requete = "SELECT * FROM wp_evenement ORDER BY id";

 // connection to the database
 try {
 $bdd = new PDO('mysql:host=***.mysql.db;dbname=****', '***', '***');
 } catch(Exception $e) {
  exit('Unable to connect to database.');
 }
 // Execute the query
 $resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));

 // sending the encoded result to success page
 echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));

?>

尝试使用$ wpdb 可行!

    <?php

    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php';
    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';
    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php';


    // List of events
    $json = array();

    // Query that retrieves events
    global $wpdb;
    $requete = "SELECT * FROM wp_evenement ORDER BY id";

    // Execute the query
    $resultat = $wpdb->get_results($requete);

    // sending the encoded result to success page
    echo json_encode($resultat);

?>

推荐答案

尝试以下代码.

<?php

    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php';
    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';
    include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php';


    // List of events
    $json = array();

    // Query that retrieves events
    global $wpdb;
    $requete = "SELECT * FROM wp_evenement ORDER BY id";

    // Execute the query
    $resultat = $wpdb->get_results($requete);

    // sending the encoded result to success page
    echo json_encode($resultat);

?>

您的代码有拼写错误

尝试$wpbd

这篇关于关于Wordpress集成的FullCalendar-wpdb和json问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆