Solved, thanks.
add_filter( 'tablepress_shortcode_table_default_shortcode_atts', 'tablepress_add_shortcode_parameter_auto_filter' );
add_filter( 'tablepress_table_js_options', 'tablepress_add_auto_filter_js_options', 10, 3 );
add_filter( 'tablepress_datatables_parameters', 'tablepress_auto_filter_parameter', 10, 4 );
/**
* Add "datatables_auto_filter" as a valid parameter to the [table /] Shortcode.
*
* @since 1.0
*
* @param array $default_atts Default attributes for the TablePress [table /] Shortcode.
* @return array Extended attributes for the Shortcode.
*/
function tablepress_add_shortcode_parameter_auto_filter( $default_atts ) {
$default_atts['datatables_auto_filter'] = false;
return $default_atts;
}
/**
* Pass "datatables_auto_filter" from Shortcode parameters to JavaScript arguments.
*
* @since 1.0
*
* @param array $js_options Current JS options.
* @param string $table_id Table ID.
* @param array $render_options Render Options.
* @return array Modified JS options.
*/
function tablepress_add_auto_filter_js_options( $js_options, $table_id, $render_options ) {
$js_options['datatables_auto_filter'] = $render_options['datatables_auto_filter'];
return $js_options;
}
/**
* Evaluate "datatables_auto_filter" parameter and add corresponding JavaScript code, if needed.
*
* @since 1.1
*
* @param array $parameters DataTables parameters.
* @param string $table_id Table ID.
* @param string $html_id HTML ID of the table.
* @param array $js_options JS options for DataTables.
* @return array Extended DataTables parameters.
*/
function tablepress_auto_filter_parameter( $parameters, $table_id, $html_id, $js_options ) {
if ( empty( $js_options['datatables_auto_filter'] ) ) {
return $parameters;
}
// Check if we are on a product page in the "Lega Basket Femminile Serie A1 - Italia" category (ID 569)
if ( is_product() && has_term( '569', 'product_cat', $GLOBALS['post'] ) ) {
// Get the custom field 'usergiocatrice'
$usergiocatrice = get_field('usergiocatrice');
$nomecalciatore = $usergiocatrice ? $usergiocatrice : ''; // Fallback to empty if no value is found
} else {
// Default case, use product title
global $product;
$nomecalciatore = $product->get_title();
}
// Set the search parameter
$parameters['search.search'] = '"search":{"search":"' . $nomecalciatore . '"}';
return $parameters;
}
Hi,
good to see that you found a solution for your problem!
Best wishes,
Tobias