jquery - Storing current page WP list table HTML data into a PHP variable

I am trying to store my render post table HTML data of just the table into a PHP variable after the table is completely

I am trying to store my render post table HTML data of just the table into a PHP variable after the table is completely loaded.

I've tried to store:

$table = new Custom_Table_Example_List_Table();
$tablehtml = $table->display();

But this returns an array, not the full rendered table.. (e.g <table>...</table>).

I have tried using JS var table = $(#tableid").html and with document.write to fire, but keeps coming back as undefined. But if I tie it to a click action of a button, the HTML data shows fine.

It may seem as if I would need to capture the data AFTER the system knows that the table and jQuery is loaded fully.

I am trying to store my render post table HTML data of just the table into a PHP variable after the table is completely loaded.

I've tried to store:

$table = new Custom_Table_Example_List_Table();
$tablehtml = $table->display();

But this returns an array, not the full rendered table.. (e.g <table>...</table>).

I have tried using JS var table = $(#tableid").html and with document.write to fire, but keeps coming back as undefined. But if I tie it to a click action of a button, the HTML data shows fine.

It may seem as if I would need to capture the data AFTER the system knows that the table and jQuery is loaded fully.

Share Improve this question edited Sep 12, 2019 at 23:50 Sally CJ 40.3k2 gold badges29 silver badges50 bronze badges asked Sep 12, 2019 at 20:50 samjco-comsamjco-com 5996 silver badges19 bronze badges 3
  • To put the table HTML in a PHP variable, you can use output buffering. But you could also do something like <div id="my-table-wrapper"><?php $table->display(); ?></div> and use jQuery( '#my-table-wrapper > table' ) to get the table element via JS. (WordPress doesn't add an id to the table tag) – Sally CJ Commented Sep 12, 2019 at 23:53
  • Yes I've tested that. $table->display(); seems to be an array – samjco-com Commented Sep 13, 2019 at 2:53
  • Which "that"? Have you tried output buffering: ob_start(); $table->display(); $tablehtml = ob_get_clean(); ? – Sally CJ Commented Sep 13, 2019 at 12:09
Add a comment  | 

1 Answer 1

Reset to default 0

Ah!

function callback($buffer) {
  // modify buffer here, and then return the updated code return $buffer;
}

function buffer_start() {
  ob_start("callback");
}

function buffer_end() {
  ob_end_flush();
}

add_action('wp_head', 'buffer_start');
add_action('wp_footer', 'buffer_end');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745159558a4614327.html

相关推荐

  • jquery - Storing current page WP list table HTML data into a PHP variable

    I am trying to store my render post table HTML data of just the table into a PHP variable after the table is completely

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信