Wordpress data not appearing using Editor Datable with server side processing

Wordpress data not appearing using Editor Datable with server side processing

looqstudiolooqstudio Posts: 4Questions: 0Answers: 0

I've been trying to get the editor table to pull through data from my WordPress posts.
I eventually want to only get a specific post type. But for the time being, I can't even get any data to display.

I've been able to recreate the example files on my own WordPress page, so I know that I've installed the editor correctly.

I don't know what I'm missing from my code. Any help in the right direction would be much appreciated.

HTML:

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>Type</th>
            <th>Status</th>
            <th>Name</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th></th>
            <th>Type</th>
            <th>Status</th>
            <th>Name</th>
        </tr>
    </tfoot>
</table>

Javascript:

<script>
var editor; // use a global for the submit and return data rendering in the examples
 
$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "https://emotiondevolp.wpengine.com/Editor-PHP-2.0.8/controllers/all_post_table.php",
        table: "#example",
        fields: [ {
                label: "Type:",
                name: "wm_ew_posts.post_type"
            }, {
                label: "Status:",
                name: "wm_ew_posts.post_status"
            }, {
                label: "Name:",
                name: "wm_ew_users.display_name"
            }, 
        ]
    } );
 
    // Activate an inline edit on click of a table cell
    $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editor.inline( this, {
            onBlur: 'submit'
        } );
    } );
 
    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "https://emotiondevolp.wpengine.com/Editor-PHP-2.0.8/controllers/all_post_table.php",
            type: 'POST'
        },
        columns: [
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            },
            { data: "wm_ew_posts.post_status" },
            { data: "wm_ew_posts.post_type" },
            { data: "wm_ew_posts.post_author" },
            { data: "wm_ew_users.display_name" }
        ],
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );
</script>

Server Script:

<?php
 
// DataTables PHP library
include( "../lib/DataTables.php" );
 
// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;
 
 
/*
 * Example PHP implementation used for the join.html example
 */
Editor::inst( $db, 'wm_ew_posts' )
    ->field(

        Field::inst( 'wm_ew_posts.post_status' ),
        Field::inst( 'wm_ew_posts.post_type' ),
        Field::inst( 'wm_ew_posts.post_author' ),
            ->options( Options::inst()
                ->table( 'wm_ew_users' )
                ->value( 'ID' )
                ->label( 'display_name' )
            )
            ->validator( Validate::dbValues() ),
        Field::inst( 'wm_ew_users.display_name' )
    )
    ->leftJoin( 'wm_ew_users', 'wm_ew_users.ID', '=', 'wm_ew_posts.post_author' )
    ->process($_POST)
    ->json();

Replies

  • allanallan Posts: 56,888Questions: 1Answers: 9,041 Site admin

    https://emotiondevolp.wpengine.com/Editor-PHP-2.0.8/controllers/all_post_table.php

    Is returning an empty response. That presumably isn't expected? Or would I need to be logged in to see a response?

    Allan

  • looqstudiolooqstudio Posts: 4Questions: 0Answers: 0

    Hey Allan,

    I'm getting the same empty response when I'm logged in.

    I'm guessing the type of data, that I'm trying to get should only be visible to admins in the backend of WordPress.

    So am I missing something in the server-side script to get WordPress post-type data?

    I can record a quick video, showing my setup including the database.

  • allanallan Posts: 56,888Questions: 1Answers: 9,041 Site admin

    I'd suggest checking the server's error logs, or enabling all debug output using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    to see if there is an error being reported.

    Allan

  • looqstudiolooqstudio Posts: 4Questions: 0Answers: 0

    Do I just add the above code to the end of my server-side script?

  • allanallan Posts: 56,888Questions: 1Answers: 9,041 Site admin

    No - at the start of it, immediately after the opening <?php.

    Allan

  • looqstudiolooqstudio Posts: 4Questions: 0Answers: 0

    I've done that, but I don't see any new error message

    <?php
     
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
     
    // DataTables PHP library
    include( "../lib/DataTables.php" );
     
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
     
     
    /*
     * Example PHP implementation used for the join.html example
     */
    Editor::inst( $db, 'wm_ew_posts' )
        ->field(
    
            Field::inst( 'wm_ew_posts.post_status' ),
            Field::inst( 'wm_ew_posts.post_type' ),
            Field::inst( 'wm_ew_posts.post_author' ),
                ->options( Options::inst()
                    ->table( 'wm_ew_users' )
                    ->value( 'ID' )
                    ->label( 'display_name' )
                )
                ->validator( Validate::dbValues() ),
            Field::inst( 'wm_ew_users.display_name' )
        )
        ->leftJoin( 'wm_ew_users', 'wm_ew_users.ID', '=', 'wm_ew_posts.post_author' )
        ->process($_POST)
        ->json();
        
    
  • allanallan Posts: 56,888Questions: 1Answers: 9,041 Site admin

    I think in that case you’d need to check your web server’s error logs to see if there is anything reported there. Those two lines should really show any error messages - but they can be overridden with certain PHP configurations.

    Allan

Sign In or Register to comment.