Hi,
thanks for your question.
Yes, there are “Template Tag” functions that you can use anywhere in the theme. For more information on these, please take a look at the corresponding section in the documentation at http://tablepress.org/documentation/
You could then combine that with some PHP code that retrieves the value of a custom field and inserts that as the table ID into the Template Tag function.
Another idea would be to use a plugin like Widget Logic from http://wordpress.org/extend/plugins/widget-logic/ which allows you to show a different text widget on different posts/pages. You could then have different text widgets with a different table Shortcode each.
Regards,
Tobias
Hi Tobias,
Thanks for the quick response! The first option looks a little daunting with my limited knowledge of PHP. The widget looks like a promising solution but I read that anyone with access to it can possibly add malicious code. Since I would have multiple contributors who need to be able to add the table in this way, it is a likely vulnerability that I would rather not risk.
The main obstacle is combining the table template tag with the custom function code.
get_post_meta($post->ID, 'key', true);
tablepress_print_table( array( 'id' => '1', 'use_datatables' => true, 'print_name' => false ) )
Hi,
yes, the first option would require some small PHP code in the sidebar area of the theme, while the second method would indeed open the possibility of entering malicious PHP code.
However, for the first option, combining the custom field with the Template Tag function is not that difficult:
$table_id = get_post_meta( $post->ID, 'sidebar_tablepress_table_id', true );
if ( ! empty( $table_id ) )
tablepress_print_table( array( 'id' => $table_id ) );
With that, you would just have to add a custom field named sidebar_tablepress_table_id
to the post.
Regards,
Tobias