• Resolved calle81

    (@calle81)


    Hi, I donated to you a while ago for downloading tablepress-datatables-auto-filter/tablepress-datatables-auto-filter.php. I’ve been using it for a while now with a change to the code to filter the rows based on $nomecalciatore = $product->get_title(); . The modified code is

    function tablepress_auto_filter_parameter( $parameters, $table_id, $html_id, $js_options ) {
    if ( empty( $js_options['datatables_auto_filter'] ) ) {
    return $parameters;
    }
    global $product;
    $nomecalciatore = $product->get_title();

    $parameters['search.search'] = '"search":{"search":"' . $nomecalciatore . '"}';
    return $parameters;

    }

    . I wanted to know if you can tell me a change to the code to make so that in case the filter via $nomecalciatore = $product->get_title(); does not produce results, perform a new search via $usergiocatrice = get_field( ‘usergiocatrice’ ); or if it’s simpler, show me all the results it finds both for $nomecalciatore = $product->get_title(); and for $usergiocatrice = get_field( ‘usergiocatrice’ );. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter calle81

    (@calle81)

    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;
    }
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    good to see that you found a solution for your problem!

    Best wishes,
    Tobias

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Small change requested tablepress-datatables-auto-filter’ is closed to new replies.