Wordpress: execute do_shortcode() inside ajax function

前端 未结 1 421
走了就别回头了
走了就别回头了 2021-01-27 03:44

I\'m implementing a wordpress frontend php page which holds a list of hyperlinks in the body and a wpdatatable in the footer.

I want to reload the data table each time t

相关标签:
1条回答
  • 2021-01-27 03:56

    You need to change your function to:

    function tenders_shortcode() {
        echo do_shortcode("[wpdatatable id=49 var1=".$_POST['id']." var2=".$GLOBALS['cgv']['archive']."]");
        wp_die(); //Added
    }
    
    add_action('wp_ajax_tenders_shortcode', 'tenders_shortcode'); // add action for logged users
    add_action( 'wp_ajax_nopriv_tenders_shortcode', 'tenders_shortcode' ); // add action for unlogged users
    

    Without wp_die() at the end of the function it will never return anything other than zero.

    0 讨论(0)
提交回复
热议问题