• Resolved Le Van Toan

    (@levantoan)


    I’m run echo do_shortcode('[table id=1 /]'); in my ajax. But it don’t run shortcode. It show ‘[table id=1 /]’
    Tell me where I wrong?

    FUll code

    add_action( 'wp_ajax_load_tablepress', array( $this, 'load_tablepress_func') );
                    add_action( 'wp_ajax_nopriv_load_tablepress', array( $this, 'load_tablepress_func') );
    
    function load_tablepress_func(){                
                    ob_start();
                    echo do_shortcode('[table id=1 /]');
                    $content = ob_get_clean();
                    wp_send_json_success($content);
                    die();
                }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Your code is probably running to early. Shortcodes are not available until after the init hook.
    In addition, they are only added on the frontend, but not for admin AJAX requests.

    To counter that, you might need to add this:

    TablePress::$controller = TablePress::load_controller( 'frontend' );
    

    Then, you should also use the Template Tag, and not parse a Shortcode:

    function load_tablepress_func() {
        TablePress::$controller = TablePress::load_controller( 'frontend' );
        $content = tablepress_get_table( array(
            'id' => '1',
        ) );
        wp_send_json_success($content);
        die();
    }
    

    Regards,
    Tobias

    Thread Starter Le Van Toan

    (@levantoan)

    Hello @tobiasbg,

    Perfect, It’s okie now. Thank so much

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How I can load tablepress via ajax?’ is closed to new replies.