Hi,
thanks for your post, and sorry for the trouble.
I’m afraid that your code won’t work like this. You are basically already printing the Shortcode output on the init hook, which is too early, as it hasn’t been registered then, yet.
Can you maybe elaborate what you are trying to achieve, so that I can make suggestions?
Regards,
Tobias
Thanks for reply.
I try to print the table in a pdf.
When I click “print” I process some parameter in the post variable and print the page with the mpdf library.
Regards
Hi,
but then the Shortcode should already be in the page?!
I assume that the problem (with the default post/page content) also is that the Shortcode is printed instead of the table? Is the POST request going to the admin area or to the frontend?
Regards,
Tobias
Hi,
I print shortcode in a frontend.
Regards
Hi,
then, just use the Shortcode in the post/page content or the TablePress Template Tags in PHP. That’s the best solution for this.
Regards,
Tobias
I did not understand.
I use the shortcode in template but i render all in the pdf insted in html page.
Hi,
the question is how that PDF saving works, i.e. when its request executes, and in which context. What is the URL for the save request?
Regards,
Tobias
I think, the problem is that I process $_POST in the init hook and I use the shortcode. The hook init is too early. What is the good hook for the shortcode?
I simplify the code for you:
add_action('init', 'process_post', 21);
function process_post() {
if (isset($_GET['output']) && $_GET['output'] == 'pdf') {
if (shortcode_exists('table')) {
echo "EXIST";
} else {
echo "NOT EXIST";
}
echo do_shortcode('[table id=1 /]');
exit();
}
}
The result is : NOT EXIST [table id=1 /]
Hi,
ok, and what is the URL that you are calling to see this output?
Regards,
Tobias
Hi,
I resolve the problem with the function tablepress_print_table(array('id' => $flip[$post_obj->ID]));
Thanks!
Hi,
very nice! Yes, that’s what I meant. The Template Tag Functions are the proper way to go here.
Best wishes,
Tobias
Hi Tobias!
Similar but different problem:
I’ve added a function that sends an email to all subscribers when a new post has been published but it does not parse the tablepress shortcodes when I try to use the following:
add_action('publish_post', 'notify_subscribers_new_post');
function notify_subscribers_new_post() {
//email code...
$emailcontent = do_shortcode(apply_filters('the_content', $post->post_content, false));
}
I’m guessing do_shortcode is being called before the plugin knows what to do with it? Anyway around this?
Hi,
you are correct, TablePress does not load its Shortcodes in the admin area (where your code is run).
To work around that, please try using the code from the post https://wordpress.org/support/topic/tablepress-apple-news?replies=16#post-8277314
Regards,
Tobias
Awesome that worked! 🙂
I will donate something on your wordpress plugin page in return for spreading the coding love.
Regards from Rotterdam,
Balthazar