This add-on integrates with the TablePress plugin by allowing you to use any Pod as a data source.
Requirements
Requires WordPress 5.5+, Pods 2.7+, TablePress 1.12+, and PHP 5.6+
What does this add-on do?
Power up the [table] shortcode with Pods integration
The shortcode integration allows for using any Pod as a data source. You MUST have a skeleton Table created with TablePress as the [table] shortcode won’t work without that.
This integration requires custom shortcode attributes to be used, it does not add any additional user interfaces when managing tables. It overrides the entire table column/row output.
Available shortcode attributes for [table]
id
– This is not added by the Add-On but is required by the shortcode itself. You must create a TablePress table and provide that ID in this attribute for Pods to take over.pods_name
– The name of the pod you want to source data from. This is required for the integration to take over the TablePress table.pods_fields
– The list of fields (comma-separated) in the order to be shown in the table. Defaults to showing all fields.pods_linked_field
– The field name to automatically link the output from to the permalink of the corresponding item.pods_limit
– The number of items to show in the table. Defaults to 1000. Warning: Using queries that do not limit to a maximum number can produce problematic performance issues on your site.pods_where
and others – See the find() doc page for all supported parameters. Each parameter in the shortcode should be prefixed with “pods_”.
Example: Show all fields for the pod
[table id=123 pods_name="your_pod"]
Example: Show specific fields for the pod
[table id=123 pods_name="your_pod" pods_fields="post_title,field1,field2"]
Example: Show specific fields for the pod with one of them linked to the permalink of the item
[table id=123 pods_name="your_pod" pods_fields="post_title,field1,field2" pods_linked_field="post_title"]
Example: Show specific fields for the pod (all items from the database).
Warning: Using queries that do not limit to a maximum number (default: 1000) can produce problematic performance issues on your site.
[table id=123 pods_name="your_pod" pods_fields="post_title,field1,field2" pods_limit="-1"]
Example: find() parameter support
See the find() doc page for more parameters. Each parameter in the shortcode should be prefixed with “pods_”.
[table id=123 pods_name="your_pod" pods_where="field1.meta_value = '1'"]
You can further customize the integration through filters
There are filters available to further customize the TablePress integration to suit your needs.
Customize column labels
See the Gist.
/** * Customize the TablePress columns to use. * * @param array $columns The list of columns to be used. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. * * @return array The list of columns to be used. */ my_custom_pods_pro_tablepress_data_columns( $columns, $pod_name, $pod, $params, $table, $render_options ) { $columns['my_column'] = 'My custom label'; return $columns; } add_filter( 'pods_pro_tablepress_data_columns', 'my_custom_pods_pro_tablepress_data_columns', 10, 6 );
Customize column values using templates with magic tags
See the Gist.
/** * Customize column values using templates with magic tags * * @param array $custom_column_templates The list of custom column templates to be used, with the field name as the key. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. * * @return array The list of custom column templates to be used, with the field name as the key. */ my_custom_pods_pro_tablepress_data_custom_column_templates( $custom_column_templates, $pod_name, $pod, $params, $table, $render_options ) { // my_column_template would be a Pods Template with content like "{@website,esc_url}" which can be used in the HTML in it. $custom_column_templates['my_column'] = 'my_column_template'; return $custom_column_templates; } add_filter( 'pods_pro_tablepress_data_custom_column_templates', 'my_custom_pods_pro_tablepress_data_custom_column_templates', 10, 6 );
Filter reference
The full list of each filter and how they are called can be found below.
/** * Allow filtering the Pods limit parameter to be used. * * @since 1.0.1 * * @param int $default_limit The default limit of items to retrieve from the database (default: 1000). * @param string $pod_name The pod name. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $default_limit = apply_filters( 'pods_pro_tablepress_find_default_limit', 1000, $pod_name, $table, $render_options ); /** * Allow filtering the Pods::find() parameters to be used. * * @since 1.0.0 * * @param array $params The Pods::find() parameters to be used. * @param string $pod_name The pod name. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $params = apply_filters( 'pods_pro_tablepress_find_params', $params, $pod_name, $table, $render_options ); /** * Allow filtering the table columns to be used. * * @since 1.0.0 * * @param array $columns The list of columns to be used. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $columns = apply_filters( 'pods_pro_tablepress_data_columns', $columns, $pod_name, $pod, $params, $table, $render_options ); /** * Allow filtering the custom column templates to be used. * * @since 1.0.0 * * @param array $custom_column_templates The list of custom column templates to be used, with the field name as the key. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $custom_column_templates = apply_filters( 'pods_pro_tablepress_data_custom_column_templates', $custom_column_templates, $pod_name, $pod, $params, $table, $render_options ); /** * Allow filtering the row value for a specific column. * * The $column variable is the column name. * * @since 1.0.1 * * @param string $value The column value. * @param string $column The column name. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $value = apply_filters( "pods_pro_tablepress_data_row_value_{$column}", $value, $column, $columns, $pod_name, $pod, $params, $table, $render_options ); /** * Allow filtering the row value for any column. * * @since 1.0.1 * * @param string $value The column value. * @param string $column The column name. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $value = apply_filters( 'pods_pro_tablepress_data_row_value', $value, $column, $columns, $pod_name, $pod, $params, $table, $render_options ); /** * Allow filtering the list of rows to be used. * * @since 1.0.0 * * @param array $rows The list of rows to be used, with the field name as the key on each field in the row. * @param array $columns The list of columns to be used. * @param string $pod_name The pod name. * @param Pods $pod The Pods object. * @param array $params The Pods::find() parameters to be used. * @param array $table The TablePress information. * @param array $render_options The TablePress render options. */ $rows = apply_filters( 'pods_pro_tablepress_data_rows', $rows, $columns, $pod_name, $pod, $params, $table, $render_options );