Okay
  Public Ticket #2344360
do_shortcode out of loop
Closed

Comments

  • Volendam_Music started the conversation

    Hi support, 

    I'm trying to echo do_shortcode('[wpdatatable id=x var1=y]') out of the  wordpress loop from a php file in my child theme. The table is set up with your UX, the php code only serves to change var1 so the SQL query and resulting table data changes.

    Now I can't get the shortcode to actually render the table. I've included wp-load.php and using if ( shortcode_exists( 'wpdatatable' ) ) { echo "The shortcode exists";} I get told the shortcode exists. 

    The script only outputs an unfinished html table with the first 10 rows.

  •  2,513
    Aleksandar replied

    Hello Volendam_Music

    Thank you for your purchase.

    You need to add the code in functions.php file of the theme you're currently using; or the same file of the child theme (if you're using the child theme). The difference between child and original theme is that when you update the theme, all hooks from functions.php file will be deleted, whilst they will not be deleted in the child.

    The data is being sent with the POST method, so you can use WordPress' hook the_content, where the data can be taken from the POST and forwarded to do_shortcode function. There, our shortcode can be placed with the placeholder %VAR1% like in the following example:

    function test($content){
     if (isset($_POST['wdt_details_data'])){
     $detailsData= json_decode(stripslashes($_POST['wdt_details_data']), true);
     $content .= do_shortcode('[wpdatatable id=1 var1='y']');
    }
    return $content;
    }

    You may just need to paste the placeholder in single quotes ( 'y' ).

    I hope that helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Volendam_Music replied

    Hi Aleksandar, 

    Thank you for your reply. I'm actually trying to work with ajax so the page doesn't refresh every time. I've set up everything on the page itself so it sends the relevant data to php and places the returning table in the relevant div.

    The problem - as far as I'm aware - starts when my own php script tries to execute echo do_shortcode('[wpdatatable id=x var1 =y]'). It tells me the shortcode exists but doesn't ever return a finished table. It just creates an unstyled one with only the first 10 of 200 rows.

    My php script looks like this: 

    $path = $_SERVER['DOCUMENT_ROOT'];
        include_once $path . '/wp-config.php';
        include_once $path . '/wp-load.php';
        include_once $path . '/wp-includes/wp-db.php';
        include_once $path . '/wp-includes/pluggable.php';
        define('WP_USE_THEMES', false);

    $d = Date('Y-m-d', strtotime($_GET['d']));
    $c = $_GET['c'];
    $b = $_GET['b'];

    $shortcode = '[wpdatatable id=3 var1='.$b.' var2='.$d.' var3='.$c.']';
    echo do_shortcode( "$shortcode" );





  •  2,513
    Aleksandar replied

    Hello again Volendam_Music

    Some of our scripts aren't loaded. If I understood you correctly, you wish to render the table outside of WordPress, so probably not all scripts are loaded.

    Can you send us the link, so we can see and check which errors you have in the console and in the network tab? We need to see if the Ajax call is even being sent.

    Please note that this is a public ticket, so if your data is sensitive, please make sure to enable the Private response.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •   Volendam_Music replied privately
  •   Aleksandar replied privately