Actions and Filters
There are a number of filters provided in Posts Table Pro which allow you to customize the behavior of the plugin.
Please note that these code snippets are aimed at developers. If you feel comfortable using them, our article on how to use code snippets can serve as a helpful guide. However, if you don't feel comfortable using them, then you can use our plugin customization service.
Filters
Language filters
There are various filters provided for manipulating text strings and messages used in the plugin. Please refer to this article for filters to override the text strings.
posts_table_minimum_search_term_length
Sets the minimum search term length (number of characters) which is considered a valid search term in the search box above the table. Below this number of characters, a search is not performed.
Arguments/return
int - The minimum number of characters for a valid search term. Defaults to 2 characters.
add_filter( 'posts_table_minimum_search_term_length', function( $length ) {
return 5;
} );
posts_table_search_filter_get_terms_args
This filter modifies the arguments passed to get_terms() when building the dropdown search filters.
Arguments
array - An array of args to pass to get_terms.
string - The taxonomy for the dropdown filter
Barn2\Plugin\Posts_Table_Pro\Posts_Table_Args - The posts table args object for the current table.
Return
array- an array of args.
add_filter( 'posts_table_search_filter_get_terms_args', function( $args, $taxonomy, $table_args ) {
// Change the orderby to 'menu_order'
$args['orderby'] = 'menu_order';
return $args;
}, 10, 3 );
posts_table_search_filter_terms_<taxonomy>
This filter allows you to modify the items displayed in the dropdown search filters that appear above the table.
The filter name is dynamic, so replace the <taxonomy> portion of the filter with the taxonomy slug that you want to modify.
- For the
categoriesdropdown, use this filter:posts_table_search_filter_terms_category - For the
tagsdropdown, use this filter:posts_table_search_filter_terms_tags - For any custom taxonomy dropdown, use the taxonomy slug. For example, if your taxonomy is called
city, the filter would be:posts_table_search_filter_terms_city.
Arguments
WP_Term[] - An array of WP_Term objects to be included in the dropdown list.
Barn2\Plugin\Posts_Table_Pro\Posts_Table_Args - The posts table args object for the current table.
Return
WP_Term[]- an array of term objects.
add_filter( 'posts_table_search_filter_terms_category', function( $terms, $table_args ) {
// Remove the 'hampshire' term from the category dropdown.
foreach ( $terms as $i => $term ) {
if ( 'hampshire' === $term->slug ) {
unset( $terms[$i] );
}
}
return $terms;
}, 10, 2 );
posts_table_data_filters
This filter will modify all dropdown search filters at once. Returns an array of arrays, with the column used as the top-level array key.
Arguments
array - An array of arrays for the search filters to display. Each array has the following keys: heading, taxonomy, terms.
Barn2\Plugin\Posts_Table_Pro\Posts_Table_Args - The posts table args object for the current table.
Return
array- an array of arrays.
add_filter( 'posts_table_data_filters', function( $filters, $table_args ) {
// Do something with the filters, e.g:
$filters['categories']['heading'] = 'Choose a category';
return $filters;
}, 10, 2 );
posts_table_data_config
Filters which allows you to override the inline table configuration used when the DataTables script is initialised. You can use this filter, for example, to disable or enable certain table features. The following example disables the ordering/sorting feature in all tables.
Arguments
array - The table config array. This is passed to jQuery DataTables to initialize the posts table.
Barn2\Plugin\Posts_Table_Pro\Posts_Table_Args - The posts table args object for the current table.
Return
array- the config array.
// Disable column sorting
add_filter( 'posts_table_data_config', function( $config, $table_args ) {
$config['ordering'] = false;
return $config;
}, 10, 2 );
posts_table_open_posts_in_new_tab
Posts tables contain various links to the single post page, depending on the links option. For example, the name and button columns are normally formatted as a link to the post.
These links will open in the same tab by default. To open them in a new tab use the posts_table_open_posts_in_new_tab filter and return true.
Arguments/return
bool - Whether to open posts in a new tab from the table. Default false.
add_filter( 'posts_table_open_posts_in_new_tab', '__return_true' );
posts_table_process_shortcodes
By default, the plugin will strip shortcodes from the post content so any content that would appear inside these shortcodes will not appear in the table. You can enable shortcodes on a per-table basis using the shortcodes option, but if you want to enable them globally, return true from this filter.
Arguments/return
bool - Whether to process shortcodes in the table. Default false.
add_filter( 'posts_table_process_shortcodes', '__return_true' );
posts_table_run_in_search
Use to filter decide if posts tables should be displayed in the standard search results page (i.e. in the post excerpt or content that is displayed in the search results).
Normally, you would want to prevent the shortcode running within the search results, as only a snippet or excerpt of each page or post is shown in the search results. However, if you want to enable posts tables in the search results, set this filter true.
Arguments/return
bool - Whether to display posts tables in the post excerpts shown on the search results page. Default false.
add_filter( 'posts_table_run_in_search', '__return_true' );
posts_table_data_<column>
This filter allows you to modify the data for each column in the table (apart from custom taxonomies and custom fields - see below for these). It allows you to modify the HTML for each column before it is added to the table.
There is a filter available for each column in the table, in the form posts_table_data_<column>. The filter name is dynamic, so replace the <column> portion with the column that you want to modify, for example, posts_table_data_title.
For example, to modify data for the image column you would use the posts_table_data_image filter like this:
add_filter( 'posts_table_data_image', function( $image, $post ) {
// Wrap the image in an extra div.
return '<div class="foo">' . $image . '</div>';
}, 10, 2 );
The list of available data filters for each column are:
- ID:
posts_table_data_id - Title:
posts_table_data_title - Categories:
posts_table_data_categories - Tags:
posts_table_data_tags - Author:
posts_table_data_author - Date:
posts_table_data_date - Modified date:
posts_table_data_date_modified - Image:
posts_table_data_image - Content:
posts_table_data_content - Excerpt:
posts_table_data_excerpt - Status:
posts_table_data_status - Button column:
posts_table_data_button
Note: custom taxonomy and custom field columns use a slightly different format. See the following sections for details.
Arguments
string - The HTML data for the column to add to the table.
WP_Post - The current post object.
Return
string- the HTML data.
posts_table_data_custom_taxonomy_<taxonomy>
This filter allows you to modify the value of the data in a custom taxonomy column. The filter name is dynamic, so replace the <taxonomy> portion of the filter with the taxonomy slug that you want to modify. For example, if your taxonomy is called city, the filter would be posts_table_data_custom_taxonomy_city.
The filter accepts two arguments: the list of $terms for this post as a comma-separated string, and the current WP_Post object.
Here's an example to add an extra city to list of cities for each post in our city taxonomy column:
add_filter( 'posts_table_data_custom_taxonomy_city', function( $terms, $post ) {
// Append an extra city to the list of 'city' terms.
$terms .= ', ' . 'London';
return $terms;
}, 10, 2 );
Arguments
string - The formatted list of terms for the taxonomy column.
WP_Post - The current post object.
Return
string- the list of terms.
posts_table_data_custom_field
Filter which allows you to override the value of all custom fields in the table. It accepts 3 arguments – the custom field value, the custom field name and the current post object.
// Override the 'extra_notes' custom field
add_filter( 'posts_table_data_custom_field', function( $value, $field, $post ) {
if ( 'extra_notes' === $field ) {
// do something with $value
}
return $value;
}, 10, 3 );
Arguments
string - The custom field value.
string - The custom field
WP_Post - The current post object.
Return
string- the list of terms.
posts_table_data_custom_field_<field>
This filter allows you to modify the value of a custom field column, prior to it being added to the table. The <field> portion of the filter is dynanic and should be replaced by the custom field key.
// Override the 'extra_notes' custom field
add_filter( 'posts_table_data_custom_field_extra_notes', function( $value, $post ) {
// do something with $value
return $value;
}, 10, 2 );
Arguments
string - The custom field value.
WP_Post - The current post object.
Return
string- the custom field value.
posts_table_url_custom_field_link
Use this filter to override the link used for a URL custom field. This filter is applied only for valid URLs (beginning http:// or https://).
add_filter( 'posts_table_url_custom_field_link', function( $url, $field, $post ) {
// do something with $url...
return $url;
}, 10, 3 );
Arguments
string - The custom field URL.
string - The custom field key.
WP_Post - The current post object.
Return
string- the custom field URL.
posts_table_url_custom_field_text
Use this filter to override the anchor link text displayed for a URL custom field. This filter is applied only when the field value is a valid URL (beginning http:// or https://).
add_filter( 'posts_table_url_custom_field_text', function( $anchor_text, $field, $post ) {
// do something with $anchor_text
return $anchor_text;
}, 10, 3 );
Arguments
string - The custom field anchor text.
string - The custom field key.
WP_Post - The current post object.
Return
string- the custom field anchor text.
posts_table_custom_field_stored_date_format
If you are using date-based custom fields in your table, you may find that your dates are sometimes incorrectly sorted or formatted. The most likely cause of this is the date conversion functions used by the plugin which are built into PHP.
For example, dates such as “12/04/2018” are assumed to be in U.S. format with the month first. So this example date would be December 4th, 2018.
If the date is separated by dash (-), dot (.) or other symbol, it’s assumed to be a European/Australian date with the day before the month. If you’re using dates separated by a forward slash but in this format: d/m/Y, the plugin will not be able to sort these correctly, or format them if you’re using the date_format option. To fix this, you will need to set this filter.
Note: this is not related to how the custom field is actually displayed in the table - see the date_format option for controlling the date output.
add_filter( 'posts_table_custom_field_stored_date_format', function( $format, $field ) {
if ( 'despatch_date' === $field ) {
return 'd/m/Y';
}
return '';
}, 10, 2 );
posts_table_custom_field_is_eu_au_date
Use this filter to specify that a custom field in your table should be treated as a date in EU/AU format (i.e. day before month). This is an alternative to the above filter - posts_table_custom_field_stored_date_format - which requires you specify the exact format your date is stored in. This filter instead requires a boolean true or false to indicate whether to treat the field as an EU/AU date.
The can be applied globally to all date-based custom fields, as follows:
add_filter( 'posts_table_custom_field_is_eu_au_date', '__return_true' );
Or you can use it for individual custom fields:
add_filter( 'posts_table_custom_field_is_eu_au_date', function( $is_eu_date, $field ) {
if ( 'event_date' === $field ) {
return true;
}
return false;
}, 10, 2 );
posts_table_taxonomy_is_eu_au_date
Use this filter to specify that a custom taxonomy column in your table should be treated as a date in EU/AU format (i.e. day before month). This can be applied globally to all date-based taxonomies as follows:
add_filter( 'posts_table_taxonomy_is_eu_au_date', '__return_true' );
Or you can use it for individual taxonomies:
add_filter( 'posts_table_taxonomy_is_eu_au_date', function( $is_eu_date, $tax ) {
if ( 'event_date' === $tax ) {
return true;
}
return false;
}, 10, 2 );
posts_table_acf_value
Filters which allows you to override the custom field values returned from Advanced Custom Fields. It accepts 3 arguments – the custom field value, the ACF field object and the current post ID.
add_filter( 'posts_table_acf_value', function( $value, $field_obj, $post_id ) {
if ( 'file' === $field_obj['type'] ) {
// do something with $value
}
return $value;
}, 10, 3 );
posts_table_button_column_button_text
Filter the text used for the button element when using the button column in the table. The text is set via the Plugin Settings page or the button_text shortcode option. You can use this filter to add more complex formatting around the text.
add_filter( 'posts_table_button_column_button_text', function( $text ) {
return '<span>' . $text . '</span>';
} );
posts_table_button_column_button_class
Filter the CSS class for the button element when using the button column in the table. Defaults to: button btn posts-table-button
add_filter( 'posts_table_button_column_button_class', function( $class ) {
return $class . ' custom-btn';
} );
posts_table_more_content_text
Filter which controls the text/HTML appended when data in the content or excerpt columns is truncated. Defaults to ….
add_filter( 'posts_table_more_content_text', function( $more_text ) {
return ' [...]';
} );
posts_table_separator_<type>
Filter which allows you to change the separator used between categories, tags, terms and custom fields. For example, a post can have multiple categories, each separated by a comma. This filter allows you to change the comma for a different character, line breaks, or other custom HTML.
The filter must include the relevant type. Possible values for type are: categories, tags, terms, custom_field, and custom_field_row.
For example, to change the separator between categories in the table, add this filter:
add_filter( 'posts_table_separator_categories', function( $sep ) {
return '<br/>';
} );
posts_table_custom_class
Use this filter to add additional CSS classes to the posts table's <table> element. Type: string
add_filter( 'posts_table_custom_class', function( $class ) {
return 'feature-table';
} );
posts_table_row_class
Use this filter to add extra CSS classes to each row in the table, or selectively based on the current post. Type: array
add_filter( 'posts_table_row_class', function( $class, WP_Post $post ) {
if ( 23 === $post->ID ) {
$class[] = 'featured';
}
return $class;
}, 10, 2 );
posts_table_row_attributes
Use this filter to add extra attributes (e.g. data attributes) to the <tr> element in the table. Should return an array of attribute pairs in the format key => value.
add_filter( 'posts_table_row_attributes', function( $attributes, $post ) {
$attributes['data-foo'] = 'bar';
return $attributes;
}, 10, 2 );
posts_table_column_class_<column>
This filter allows you to add additional CSS classes to columns (i.e. the <td> cells) in the table. Replace <column> with the column that you want to add the class to. You may add additional classes, but do not remove any from the list passed in, as it may affect the operation of the table.
add_filter( 'posts_table_column_class_title', function( $classes ) {
$classes[] = 'highlight';
return $classes;
} );
posts_table_column_heading_<column>
Filter which allows you to override a column heading for all posts tables on your site. If a custom heading is specified within the shortcode itself (in the columns option), then it will take priority over the value returned from this filter.
add_filter( 'posts_table_column_heading_title', function( $heading ) {
return 'My Title';
} );
posts_table_column_priority_<column>
Filter which allows you to override a column priority for all posts tables on your site. If a priority is specified within the shortcode itself (using the priorities option), then it will take priority over the value returned from this filter.
add_filter( 'posts_table_column_priority_date', function( $priority ) {
return 10;
} );
posts_table_column_width_<column>
Filter which allows you to override a column width for all posts tables on your site. If a width is specified within the shortcode itself (using the widths option), then it will take priority over the value returned from this filter.
add_filter( 'posts_table_column_width_author', function( $width ) {
return '100px';
} );
posts_table_column_searchable_<column>
This filter allows you to set whether or not a column is “searchable” in the posts table. If a column is searchable, it means that the column will be used when the user types something into the search box above the table.
By default, the plugin includes all columns for searching, except for the image column. To override this behavior, use this filter with the appropriate column name added to the filter.
E.g. to exclude the title column from the table search:
add_filter( 'posts_table_column_searchable_title', '__return_false' );
If you wish to disable searching for a custom field or taxonomy, use the column name without the cf: or tax: prefix:
add_filter( 'posts_table_column_searchable_my_custom_field', '__return_false' );
posts_table_column_sortable_<column>
This filter allows you to set whether or not a column is “sortable” in the posts table. If a column is sortable, the table can be re-ordered by that column using the up/down arrows that appear in the column heading.
Sorting is enabled for all columns except image.
E.g. to prevent the table being sorted by title:
add_filter( 'posts_table_column_sortable_title', '__return_false' );
See the note above about using this filter for custom field or taxonomy columns.
posts_table_data_cache_expiry
Filter which allows you to set the expiry time (in seconds) for the table data cache. The default cache expiry time is 6 hours, and is configured via the plugin settings.
add_filter( 'posts_table_data_cache_expiry', function( $expiry, $cache ) {
return 3 * DAY_IN_SECONDS;
}, 10, 2 );
posts_table_use_data_cache
Filter whether to use data caching globally across all posts tables. Should return true or false.
posts_table_query_args
Filter which allows you to override the query args passed to WP_Query prior to retrieving posts from the database. See WP_Query documentation for details.
add_filter( 'posts_table_query_args', function( $args, $query ) {
// do something with $args
return $args;
}, 10, 2 );
posts_table_optimize_table_query
Use this filter to disable the database query optimisations applied by Posts Table Pro. Use this if you need to directly access the post_content or post_excerpt database fields, even when the content and excerpt columns are not displayed in your posts table.
add_filter( 'posts_table_optimize_table_query', '__return_false' );
posts_table_shortcode_output
Allows you to modify the HTML returned by the [posts_table] shortcode. Takes two parameters: the HTML and the Posts_Data_Table instance.
add_filter( 'posts_table_shortcode_output', function( $html, $table ) {
// do something with HTML
return $html;
}, 10, 2 );
posts_table_load_frontend_scripts
Filter to disable the loading of the frontend scripts and styles used in Posts Table Pro. Only use this if you want to load the scripts yourself (e.g. on specific pages).
add_filter( 'posts_table_load_frontend_scripts', '__return_false' );
posts_table_use_fitvids
Filter to disable the use of FitVids script used in Posts Table Pro. FitVids is used to ensure videos are sized correctly at smaller screen sizes.
add_filter( 'posts_table_use_fitvids', '__return_false' );
posts_table_enable_select2
Filter whether to enable or disable the Select2 Javascript library. This library adds enhancements to the search filters and page length dropdown menus above and below the table. It is enabled by default. To disable it, use:
add_filter( 'posts_table_enable_select2', '__return_false' );
posts_table_facetwp_custom_args
Filter which allows you to modify the arguments passed to the post table when using the FacetWP integration.
add_filter( 'posts_table_facetwp_custom_args', function( $args ) {
$args['rows_per_page'] = 20;
return $args;
} );
posts_table_custom_table_data_<column>
Filter which allows you to add a custom column in Posts Table Pro. See this article for more details.
add_filter( 'posts_table_custom_table_data_media_type', function( $obj, $post, $args ) {
return new Posts_Table_Media_Type_Column( $post );
} );
Arguments
Abstract_Table_Data - The table data object.
WP_Post - The current post object.
Table_Args - The table arguments object.
Return
Abstract_Table_Data- the table data object.
posts_table_search_results_page_args
Filter the arguments used to display the posts table on the search results page.
add_filter( 'posts_table_search_results_page_args', function( $args, $search_query ) {
$args['search_term'] = $search_query;
return $args;
} );
Arguments
array - The table arguments.
string - The search query.
Return
array - The filtered table arguments.
posts_table_args
Filters the table arguments after shortcode/default arguments have been merged, before the DataViews table object is created.
Use this when you need to apply a global default that is not available in the plugin settings, or when you want to enforce a table option across shortcodes. Any shortcode attributes have already been parsed by this point, so your callback can inspect or override the final argument array.
Arguments
array - The table arguments.
Return
array - The modified table arguments.
add_filter( 'posts_table_args', function( $args ) {
if ( empty( $args['rows_per_page'] ) || $args['rows_per_page'] > 50 ) {
$args['rows_per_page'] = 50;
}
return $args;
} );
posts_table_dataviews_i18n
Filters the text strings passed to the DataViews frontend.
This only affects the new DataViews frontend. It is useful for changing labels such as the search text, reset button text, pagination labels, and other interface strings without editing the JavaScript bundle.
Arguments
array - The DataViews i18n strings.
Return
array - The modified strings.
add_filter( 'posts_table_dataviews_i18n', function( $strings ) {
$strings['search'] = 'Find posts';
$strings['resetButton'] = 'Clear filters';
return $strings;
} );
posts_table_dataviews_config
Filters the DataViews frontend configuration before it is returned to the browser.
This is the main filter for changing DataViews-specific behavior. The config controls columns, filters, feature flags, default state, rows-per-page options, URL syncing, and REST endpoint details. Use this for frontend behavior that cannot be changed with shortcode options.
Arguments
array - The DataViews config.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\View_Args - The view arguments.
Return
array - The modified DataViews config.
add_filter( 'posts_table_dataviews_config', function( $config, $args ) {
// Hide the active filter chips on tables using a compact layout.
if ( ! empty( $args->layout ) && 'compact' === $args->layout ) {
$config['features']['activeFilters'] = false;
}
return $config;
}, 10, 2 );
posts_table_datatables_config
Filters the legacy DataTables configuration generated by the DataViews engine compatibility layer.
This applies to tables rendered through the legacy DataTables frontend. It does not affect tables using the new DataViews frontend; use posts_table_dataviews_config for those.
Arguments
array - The DataTables config.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\View_Args - The view arguments.
Return
array - The modified DataTables config.
add_filter( 'posts_table_datatables_config', function( $config, $args ) {
// Keep automatic column widths disabled for legacy tables with many columns.
if ( count( (array) $args->columns ) > 6 ) {
$config['autoWidth'] = false;
}
return $config;
}, 10, 2 );
posts_table_prefetch_adjacent_pages
Controls whether the DataViews frontend should prefetch adjacent pages.
Prefetching can make pagination feel faster because the next or previous page may already be loaded by the time a visitor clicks. On very large or expensive tables, you may prefer to disable it to reduce REST requests.
Arguments
bool - Whether adjacent pages should be prefetched. Default true.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\View_Args - The view arguments.
Return
bool - Whether to prefetch adjacent pages.
add_filter( 'posts_table_prefetch_adjacent_pages', function( $prefetch, $args ) {
return ! empty( $args->lazy_load ) ? false : $prefetch;
}, 10, 2 );
posts_table_responsive_breakpoints
Filters the responsive breakpoint widths used by the DataViews frontend.
Breakpoints determine when columns move into responsive child rows. This is useful if your theme has a narrow content area or if you want tablets to use the mobile layout sooner.
Arguments
array - Breakpoints keyed by breakpoint name. Defaults to tablet-l, tablet-p, mobile-l, and mobile-p.
Return
array - The modified breakpoints.
add_filter( 'posts_table_responsive_breakpoints', function( $breakpoints ) {
$breakpoints['mobile-l'] = 520;
return $breakpoints;
} );
posts_table_rest_permission_check
Filters the permission check result for DataViews REST requests.
The DataViews data endpoints are public by default, similar to a normal front-end page. Use this filter if a custom site setup needs additional permission checks before returning table config or table data.
Arguments
bool|WP_Error - The permission result.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view being accessed.
WP_REST_Request|null - The REST request, or null in the current implementation.
Return
bool|WP_Error - The permission result.
add_filter( 'posts_table_rest_permission_check', function( $result, $view, $request ) {
if ( ! empty( $view->args->private_table ) && ! is_user_logged_in() ) {
return new WP_Error( 'forbidden', 'Please log in to view this table.', [ 'status' => 403 ] );
}
return $result;
}, 10, 3 );
posts_table_rest_routes
Filters the REST route objects registered for the DataViews server.
This is an advanced extension point for adding, replacing, or removing DataViews REST route controllers before they are registered with WordPress. Most customizations should use the response filters instead.
Arguments
array - The route objects.
string - The REST namespace.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Data_Source\Data_Source_Interface - The data source.
Return
array - The modified route objects.
add_filter( 'posts_table_rest_routes', function( $routes, $namespace, $data_source ) {
// Example: only alter the Posts Table Pro REST namespace.
if ( 'ptp/v1' !== $namespace ) {
return $routes;
}
return $routes;
}, 10, 3 );
posts_table_rest_config_response
Filters the DataViews config REST response.
This runs after the DataViews config has been built for a specific view. It is useful for adding frontend metadata or making final per-table adjustments before the config is returned to JavaScript.
Arguments
array - The config response.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view object.
WP_REST_Request - The REST request.
Return
array - The modified config response.
add_filter( 'posts_table_rest_config_response', function( $config, $view, $request ) {
$config['metadata']['generatedAt'] = current_time( 'mysql' );
return $config;
}, 10, 3 );
posts_table_rest_data_response
Filters the DataViews data REST response.
The response includes rows, pagination totals, and optionally filter counts. Use this filter to append additional metadata for custom frontend code, or to adjust row data after the table query has run.
Arguments
array - The response data.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view object.
WP_REST_Request - The REST request.
Return
array - The modified response data.
add_filter( 'posts_table_rest_data_response', function( $response, $view, $request ) {
$response['generatedAt'] = current_time( 'mysql' );
return $response;
}, 10, 3 );
posts_table_rest_map_request_args
Filters the mapped view arguments created from a DataViews REST data request before the view is updated.
This is useful when you need to translate custom request data into table arguments, or when you want to enforce limits on pagination, sorting, search, or filters sent by the browser.
Arguments
array - The mapped view arguments.
array - Pagination state.
array - Sorting state.
array - Filter state.
array - Search state.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view object.
Return
array - The modified view arguments.
add_filter( 'posts_table_rest_map_request_args', function( $args, $pagination, $sorting, $filters, $search, $view ) {
$args['rows_per_page'] = min( 100, (int) $args['rows_per_page'] );
return $args;
}, 10, 6 );
posts_table_auto_filter_counts
Controls whether auto filter counts are included in the DataViews data response.
Filter counts can help users see how many posts match each filter option. On very large or heavily customized tables, disabling counts can reduce query work.
Arguments
bool - Whether to include filter counts.
array - The filter IDs.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view object.
Return
bool - Whether to include filter counts.
add_filter( 'posts_table_auto_filter_counts', function( $include, $filter_ids, $view ) {
return count( $filter_ids ) <= 5 ? $include : false;
}, 10, 3 );
posts_table_scope_search_filter_terms
Controls whether dropdown filter terms should be scoped to posts matching the current table query.
When enabled, dropdown filters only show terms that exist in the current table results. Return false if you want filter dropdowns to show all matching taxonomy terms regardless of the table's current post selection.
Arguments
bool - Whether to scope the terms. Default true.
string - The taxonomy slug.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\View_Args - The view arguments.
array - The current get_terms() arguments.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Config\Abstract_Config_Builder - The config builder.
Return
bool - Whether to scope the terms.
add_filter( 'posts_table_scope_search_filter_terms', function( $scope, $taxonomy, $args, $term_args, $builder ) {
return 'category' === $taxonomy ? false : $scope;
}, 10, 5 );
posts_table_filter_counts
Filters the filter count data returned for DataViews filters.
This filter runs after counts have been calculated. Use it to remove counts for specific filters, change labels/counts for custom integrations, or merge in counts from another data source.
Arguments
array - Filter counts keyed by filter ID.
array - Requested filter IDs.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\View\Abstract_View - The view object.
Return
array - The modified filter counts.
add_filter( 'posts_table_filter_counts', function( $counts, $filter_ids, $view ) {
unset( $counts['tags'] );
return $counts;
}, 10, 3 );
posts_table_use_indexed_search
Controls whether the DataViews engine should use indexed search/query tables where available.
Return false to force the plugin to use the fallback WordPress query path. This can help when debugging indexing issues or when another search integration needs to take over the query.
Arguments
bool - Whether to use indexed search.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query|string - The view query object, or a search string when called from the standalone indexed search helper.
string|array - The plugin prefix, or search arguments when called from the standalone indexed search helper.
Return
bool - Whether to use indexed search.
add_filter( 'posts_table_use_indexed_search', function( $use_indexed, $query, $context ) {
// Temporarily bypass indexed search for troubleshooting.
if ( isset( $_GET['ptp_no_index'] ) && current_user_can( 'manage_options' ) ) {
return false;
}
return $use_indexed;
}, 10, 3 );
posts_table_search_results
Filters search results before they are cached on the DataViews query object. Return an array of WP_Post objects or post IDs.
This is the best hook for replacing the result set with results from a custom search provider while still letting Posts Table Pro handle filtering, paging, and rendering.
Arguments
array - Current search results.
string - The search term.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
array - The modified results.
add_filter( 'posts_table_search_results', function( $posts, $search_term, $query, $plugin_prefix ) {
if ( 'ptp' !== $plugin_prefix || strlen( $search_term ) < 3 ) {
return $posts;
}
return $posts;
}, 10, 4 );
posts_table_search_sql
Filters the indexed search SQL query used by the DataViews view query.
This is an advanced hook for trusted code only. If you add request-dependent values to SQL, prepare them with $wpdb->prepare().
Arguments
string - The SQL query.
string - The search term.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
string - The modified SQL query.
add_filter( 'posts_table_search_sql', function( $sql, $search_term, $query, $plugin_prefix ) {
return $sql;
}, 10, 4 );
posts_table_filter_sql
Filters the filter-only SQL query used by the indexed DataViews query path.
This runs when indexed filtering is active without a search term. Use it only for trusted SQL customizations that cannot be expressed through higher-level query hooks.
Arguments
string - The SQL query.
array - Filter conditions.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
string - The modified SQL query.
add_filter( 'posts_table_filter_sql', function( $sql, $conditions, $query, $plugin_prefix ) {
return $sql;
}, 10, 4 );
posts_table_query_conditions
Filters indexed query condition fragments. Each custom condition must start with AND.
This is safer than replacing an entire SQL query because you only add or remove individual condition fragments.
Arguments
array - SQL condition fragments.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
array - The modified condition fragments.
add_filter( 'posts_table_query_conditions', function( $conditions, $query, $plugin_prefix ) {
$conditions[] = ' AND p.post_password = ""';
return $conditions;
}, 10, 3 );
posts_table_query_results
Filters hydrated query results from the indexed query path.
The hook receives the final WP_Post objects after indexed IDs have been loaded from WordPress. Use it for final result adjustments that depend on full post objects.
Arguments
WP_Post[] - The post objects.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
WP_Post[] - The modified post objects.
add_filter( 'posts_table_query_results', function( $posts, $query, $plugin_prefix ) {
return array_filter( $posts, function( $post ) {
return ! has_term( 'hidden', 'category', $post );
} );
}, 10, 3 );
posts_table_indexed_where_clause
Adds a SQL WHERE fragment to indexed queries. The returned fragment must start with AND.
Use this for global indexed-query restrictions such as access control. The posts table is available as the p alias.
Arguments
string - Additional SQL condition. Default empty string.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
string - The SQL condition fragment.
add_filter( 'posts_table_indexed_where_clause', function( $clause, $query, $plugin_prefix ) {
return ' AND p.post_password = ""';
}, 10, 3 );
posts_table_sort_join_clause
Adds a SQL JOIN fragment for custom indexed sort columns.
Use this together with posts_table_sort_order_clause when a custom sort value lives outside the standard WordPress posts, postmeta, taxonomy, or DataViews sort index tables.
Arguments
string - The JOIN clause. Default empty string.
string - The sort column identifier.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
string - The SQL JOIN fragment.
add_filter( 'posts_table_sort_join_clause', function( $join, $sort_by, $query, $plugin_prefix ) {
if ( 'priority' !== $sort_by ) {
return $join;
}
global $wpdb;
return $wpdb->prepare(
' LEFT JOIN %i ptp_priority_meta ON ptp_priority_meta.post_id = p.ID AND ptp_priority_meta.meta_key = %s',
$wpdb->postmeta,
'priority'
);
}, 10, 4 );
posts_table_sort_order_clause
Filters the SQL ORDER BY expression for custom indexed sort columns. Return the expression without the ORDER BY keyword.
This hook is normally paired with a custom JOIN added through posts_table_sort_join_clause.
Arguments
string - The order expression. Default empty string.
string - The sort column identifier.
string - The sort direction, ASC or DESC.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
Return
string - The SQL order expression.
add_filter( 'posts_table_sort_order_clause', function( $clause, $sort_by, $order, $query, $plugin_prefix ) {
if ( 'priority' === $sort_by ) {
return "CAST( ptp_priority_meta.meta_value AS UNSIGNED ) {$order}";
}
return $clause;
}, 10, 5 );
posts_table_attribute_weights
Filters search attribute weights used for indexed relevance scoring.
Higher weights make matches in that attribute rank above lower-weight matches. Wildcards such as cf:* and tax:* can be used for groups of indexed attributes.
Arguments
array - Attribute weights, such as title, content, cf:*, and tax:*.
string - The plugin prefix. This argument is available when called by the main DataViews query.
Return
array - The modified weights.
add_filter( 'posts_table_attribute_weights', function( $weights, $plugin_prefix = '' ) {
$weights['title'] = 150;
return $weights;
}, 10, 2 );
posts_table_indexed_search_sql
Filters the SQL query used by the standalone indexed search helper.
Arguments
string - The SQL query.
string - The search query.
array - The search arguments.
Return
string - The modified SQL query.
add_filter( 'posts_table_indexed_search_sql', function( $sql, $query, $args ) {
return $sql;
}, 10, 3 );
Actions
posts_table_parse_args
Fired when the posts table arguments have been parsed and set. Takes one argument – the Barn2PluginPosts_Table_ProTable_Args instance.
posts_table_args_updated
Fired when the table args are updated. This happens, for example, when the table is filtered by category or a search term is entered. Takes one argument - the Barn2PluginPosts_Table_ProPosts_Table object.
posts_table_before_get_table
Fired once before the table is created, before the attributes and headings are added to the table. Takes one argument – the Barn2PluginPosts_Table_ProPosts_Table object.
posts_table_after_get_table
Fired once after each the table is fully created and (for standard loading) the data has been added. Takes one argument – the Barn2PluginPosts_Table_ProPosts_Table object.
posts_table_before_get_data
Fired once before the data is fetched and added to the table. Takes one argument – the Barn2PluginPosts_Table_ProPosts_Table object.
posts_table_after_get_data
Fired once after the data is added to the table. Takes one argument – the Barn2PluginPosts_Table_ProPosts_Table object.
posts_table_data_source_registered
Fires after a DataViews data source is registered.
This is an early lifecycle hook. It is useful for recording the active REST namespace or bootstrapping integrations that need access to the registered data source.
Arguments
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Data_Source\Data_Source_Interface - The registered data source.
string - The REST namespace.
add_action( 'posts_table_data_source_registered', function( $data_source, $namespace ) {
if ( 'ptp/v1' === $namespace ) {
update_option( 'ptp_dataviews_rest_namespace', $namespace, false );
}
}, 10, 2 );
posts_table_before_index_post
Fires before a post is processed by the content indexer.
Use this to clear per-post caches or prepare custom data before searchable content is extracted.
Arguments
int - The post ID.
WP_Post - The post object.
add_action( 'posts_table_before_index_post', function( $post_id, $post ) {
delete_transient( 'ptp_search_preview_' . $post_id );
}, 10, 2 );
posts_table_after_index_post
Fires after a post is processed by the content indexer.
The third argument contains the searchable attributes that were indexed, which makes this hook useful for storing lightweight indexing metadata.
Arguments
int - The post ID.
WP_Post - The post object.
array - The indexed attributes.
add_action( 'posts_table_after_index_post', function( $post_id, $post, $attributes ) {
update_post_meta( $post_id, '_ptp_last_content_indexed', current_time( 'mysql' ) );
update_post_meta( $post_id, '_ptp_indexed_attributes', array_keys( $attributes ) );
}, 10, 3 );
posts_table_before_filter_index_post
Fires before a post is processed by the filter indexer.
The filter index stores taxonomy and custom field values used by DataViews filters. This hook is useful for invalidating custom filter UI caches before new values are written.
Arguments
int - The post ID.
WP_Post - The post object.
add_action( 'posts_table_before_filter_index_post', function( $post_id, $post ) {
delete_transient( 'ptp_filter_options_' . $post->post_type );
}, 10, 2 );
posts_table_after_filter_index_post
Fires after a post is processed by the filter indexer.
Use this when you need to track when filter values were last refreshed for a post.
Arguments
int - The post ID.
WP_Post - The post object.
add_action( 'posts_table_after_filter_index_post', function( $post_id, $post ) {
update_post_meta( $post_id, '_ptp_last_filter_indexed', current_time( 'mysql' ) );
}, 10, 2 );
posts_table_before_sort_index_post
Fires before a post is processed by the sort indexer.
Use this to clear cached values for custom sort columns before the sort index is rebuilt.
Arguments
int - The post ID.
WP_Post - The post object.
add_action( 'posts_table_before_sort_index_post', function( $post_id, $post ) {
wp_cache_delete( 'ptp_sort_value_' . $post_id, 'posts-table-pro' );
}, 10, 2 );
posts_table_after_sort_index_post
Fires after a post is processed by the sort indexer.
Use this to record that sort values have been refreshed for a post.
Arguments
int - The post ID.
WP_Post - The post object.
add_action( 'posts_table_after_sort_index_post', function( $post_id, $post ) {
update_post_meta( $post_id, '_ptp_last_sort_indexed', current_time( 'mysql' ) );
}, 10, 2 );
posts_table_batch_before_process
Fires before a single post is processed in an indexing batch.
This is lower level than the content, filter, and sort indexer hooks. It runs once before the plugin processes all index types for the post.
Arguments
int - The post ID.
add_action( 'posts_table_batch_before_process', function( $post_id ) {
set_transient( 'ptp_current_indexing_post', $post_id, MINUTE_IN_SECONDS );
} );
posts_table_batch_after_process
Fires after a single post is processed in an indexing batch.
Use this for cleanup that should happen after all indexers have run for an individual post.
Arguments
int - The post ID.
add_action( 'posts_table_batch_after_process', function( $post_id ) {
delete_transient( 'ptp_current_indexing_post' );
} );
posts_table_full_index_queued
Fires when a full DataViews index rebuild is queued.
This is a good place to clear cached table output or status data that will become stale while the rebuild runs.
Arguments
array - Index arguments.
add_action( 'posts_table_full_index_queued', function( $args ) {
delete_transient( 'ptp_custom_filter_counts' );
update_option( 'ptp_dataviews_index_started', current_time( 'mysql' ), false );
} );
posts_table_before_indexing_batch
Fires before an indexing batch is processed.
The offset and limit identify the current batch. Use this to store progress metadata for an admin dashboard or custom monitoring UI.
Arguments
int - Batch offset.
int - Batch limit.
add_action( 'posts_table_before_indexing_batch', function( $offset, $limit ) {
update_option(
'ptp_dataviews_current_batch',
[
'offset' => (int) $offset,
'limit' => (int) $limit,
],
false
);
}, 10, 2 );
posts_table_after_indexing_batch
Fires after an indexing batch is processed.
Use this to store progress information after each batch completes.
Arguments
int - Number of posts processed.
int - Batch offset.
add_action( 'posts_table_after_indexing_batch', function( $processed_count, $offset ) {
update_option(
'ptp_dataviews_last_batch',
[
'offset' => (int) $offset,
'processed' => (int) $processed_count,
'finished' => current_time( 'mysql' ),
],
false
);
}, 10, 2 );
posts_table_indexing_complete
Fires when DataViews indexing is complete.
This hook is useful for clearing stale caches, marking a custom status as complete, or notifying another system that indexed search is ready.
Arguments
string - The plugin prefix.
add_action( 'posts_table_indexing_complete', function( $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
delete_transient( 'ptp_custom_filter_counts' );
update_option( 'ptp_dataviews_last_index_completed', current_time( 'mysql' ), false );
}
} );
posts_table_before_index_cleanup
Fires before the DataViews index cleanup job runs.
Use this to prepare related custom cleanup, such as clearing temporary options used by your own indexing integration.
Arguments
string - The plugin prefix.
add_action( 'posts_table_before_index_cleanup', function( $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
delete_transient( 'ptp_index_cleanup_notice' );
}
} );
posts_table_after_index_cleanup
Fires after the DataViews index cleanup job runs.
The cleanup statistics include counts for stale entries, stale filters, stale sorts, orphan tokens, and skipped rows that were cleared.
Arguments
array - Cleanup statistics.
string - The plugin prefix.
add_action( 'posts_table_after_index_cleanup', function( $stats, $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
update_option( 'ptp_last_index_cleanup_stats', $stats, false );
}
}, 10, 2 );
posts_table_after_query
Fires after the DataViews query has loaded posts.
This runs after the indexed or fallback query path has finished. Use it for lightweight follow-up work only, because it can run during normal front-end table requests.
Arguments
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Query\View_Query - The query object.
string - The plugin prefix.
add_action( 'posts_table_after_query', function( $query, $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix && method_exists( $query, 'get_total_filtered_posts' ) ) {
set_transient( 'ptp_last_filtered_post_count', $query->get_total_filtered_posts(), 5 * MINUTE_IN_SECONDS );
}
}, 10, 2 );
posts_table_index_change_listener_registered
Fires after DataViews index change listener hooks are registered.
This confirms that automatic re-indexing listeners for post, term, meta, ACF, and WooCommerce changes have been attached.
Arguments
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Indexer\Change_Listener - The change listener.
string - The plugin prefix.
add_action( 'posts_table_index_change_listener_registered', function( $listener, $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
update_option( 'ptp_index_change_listener_ready', true, false );
}
}, 10, 2 );
posts_table_orm_mappings_registered
Fires after DataViews ORM entity mappings are registered.
This is an advanced hook for integrations that need to inspect DataViews table names or register additional ORM behavior after the default mappings are ready.
Arguments
Barn2\Plugin\Posts_Table_Pro\Dependencies\DatabasePress\ORM\EntityManager - The entity manager.
string - The plugin prefix.
Barn2\Plugin\Posts_Table_Pro\Dependencies\Data_Views\Database\ORM_Service - The ORM service.
add_action( 'posts_table_orm_mappings_registered', function( $orm, $plugin_prefix, $service ) {
if ( 'ptp' === $plugin_prefix ) {
update_option( 'ptp_filter_index_table', $service->get_table_name( 'filter_index' ), false );
}
}, 10, 3 );
posts_table_before_deactivate
Fires before DataViews deactivation cleanup runs.
Use this to clear custom scheduled actions, temporary data, or cache entries that depend on the DataViews indexing runtime.
Arguments
string - The plugin prefix.
add_action( 'posts_table_before_deactivate', function( $prefix ) {
if ( 'ptp' === $prefix ) {
delete_transient( 'ptp_current_indexing_post' );
}
} );
posts_table_after_deactivate
Fires after DataViews deactivation cleanup runs.
At this point scheduled DataViews indexing jobs have been cancelled, but the index tables are kept intact.
Arguments
string - The plugin prefix.
add_action( 'posts_table_after_deactivate', function( $prefix ) {
if ( 'ptp' === $prefix ) {
update_option( 'ptp_dataviews_deactivated_at', current_time( 'mysql' ), false );
}
} );
posts_table_tables_created
Fires after DataViews database tables are created.
This runs during installer readiness checks. Use it to record table availability or initialize custom data that depends on the DataViews tables.
Arguments
string - The plugin prefix.
array - Created table instances.
add_action( 'posts_table_tables_created', function( $plugin_prefix, $tables ) {
if ( 'ptp' === $plugin_prefix ) {
update_option( 'ptp_dataviews_tables', array_keys( $tables ), false );
}
}, 10, 2 );
posts_table_tables_dropped
Fires after DataViews database tables are dropped.
This only runs if a developer or integration explicitly drops the DataViews tables.
Arguments
string - The plugin prefix.
add_action( 'posts_table_tables_dropped', function( $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
delete_option( 'ptp_dataviews_tables' );
}
} );
posts_table_tables_truncated
Fires after DataViews database tables are truncated.
Truncating tables removes indexed data while leaving the table schema in place. Use this to clear custom status values that assume indexed rows exist.
Arguments
string - The plugin prefix.
add_action( 'posts_table_tables_truncated', function( $plugin_prefix ) {
if ( 'ptp' === $plugin_prefix ) {
delete_option( 'ptp_dataviews_last_index_completed' );
}
} );