• Resolved jdobbsy1987

    (@jdobbsy1987)


    Hi,

    I’m trying to use the ACF Value of pages to change the filter on the TablePress Filter but it doesn’t appear to be working.

    This is the code i have:
    [table id=3 filter="[acf field=model_code]" filter_columns="5" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true /]

    If i replace [acf field=model_code] with the ACF Value such as filter=”mymodelcode” then it works.

    I can see in the elementor visual editor that the ACF Value displays as i would expect but thats looking at the shortcode. Once i publish and look at the actual table it doesnt filter and just appears to show all records.

    Is there something i need to do for TablePress to use the value from the ACF Field?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The cause for this essentially is that Shortcodes inside Shortcodes are not automatically evaluated by WordPress (the outer Shortcode is evaluated first, and that outer Shortcode’s handler function would then need to evaluate the inner Shortcode).
    A quick way to achieve that would be to change line 103 of the file /wp-content/plugins/tablepress-row-filter/tablepress-row-filter.php from

    $filter = $render_options['filter'];
    

    to

    $filter = do_shortcode( $render_options['filter'] );
    

    Regards,
    Tobias

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    Thank you for the fast reply.

    I have tried replacing the text on that line but it’s still not appearing to work, it doesn’t filter for the value and just shows all results still.

    Regards,
    Jamie

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    ok, can you then please use the modified Shortcode

    [table id=3 filter="[acf field=model_code]" filter_columns="5" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true shortcode_debug=true /]
    

    on the page? The added shortcode_debug=true parameter should print the actually use Shortcode parameters below the table, including the actually used value for the filter parameter. Let’s see what’s actually being used there (it could for example be possible that the ACF Shortcode is never even passed to the TablePress Extension, so that we’ll have to find a different approach).

    Regards,
    Tobias

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    Under the table i see this

    " filter_columns="5" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true shortcode_debug=true /]

    So looks like it doesnt get any filter?

    Regards,
    Jamie

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    Did some more testing this morning with fewer parameters and accidentally missed a closing ‘]’ in the acf field shortcode

    [table id=3 filter=[acf field="model_code" shortcode_debug=true]

    I then noticed the debug information

    array (
      'id' => '3',
      'column_widths' => '',
      'alternating_row_colors' => true,
      'row_hover' => true,
      'table_head' => true,
      'table_foot' => false,
      'first_column_th' => false,
      'print_name' => false,
      'print_name_position' => 'above',
      'print_description' => false,
      'print_description_position' => 'below',
      'cache_table_output' => true,
      'convert_line_breaks' => true,
      'extra_css_classes' => '',
      'use_datatables' => true,
      'datatables_sort' => true,
      'datatables_paginate' => false,
      'datatables_paginate_entries' => 10,
      'datatables_lengthchange' => true,
      'datatables_filter' => false,
      'datatables_info' => false,
      'datatables_scrollx' => false,
      'datatables_scrolly' => false,
      'datatables_custom_commands' => '',
      'datatables_locale' => 'en_GB',
      'show_rows' => '',
      'show_columns' => '',
      'hide_rows' => '',
      'hide_columns' => '',
      'cellspacing' => false,
      'cellpadding' => false,
      'border' => false,
      'shortcode_debug' => true,
      'filter' => '[acf',
      'filter_full_cell_match' => false,
      'filter_case_sensitive' => false,
      'filter_columns' => 'all',
      'filter_inverse' => false,
      'row_order' => 'default',
      'row_order_sort_column' => false,
      'row_order_sort_direction' => 'ASC',
      'row_order_manual_order' => 'all',
      'html_id' => 'tablepress-3',
      'edit_table_url' => 'https://wordpress-482191-2563283.cloudwaysapps.com/wp-admin/admin.php?page=tablepress&action=edit&table_id=3',
    )

    Can see from that it’s breaking at the space in “acf field”

    Added the missing ‘]’

    [table id=3 filter=[acf field="model_code"] shortcode_debug=true]

    And then don’t get debug information, just this

    shortcode_debug=true]

    Which suggests its breaking the shortcode

    I did also move the acf field quotation marks from around model_code to around the whole acf shortcode

    i.e. from [acf field=”model_code”] to “[acf field=model_code]”

    then it outputs this so get the same issue but now with one of the quote marks

    ” shortcode_debug=true]

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for that! This indicates that WordPress is actually ending the [table Shortcode prematurely, namely at the ] of the ACF Shortcode. We will therefore need a different approach to nest these Shortcodes.

    First, please revert the modification to the TablePress Extension from above.

    Then, please add this to your theme’s “functions.php” file. This will create a new Shortcode [table-acf] which accepts normal [table] Shortcode parameters, except with the filter parameter pre-filled with that ACF Shortcode:

    add_shortcode( 'table-acf', 'jdobbsy1987_table_acf_shortcode' );
    function jdobbsy1987_table_acf_shortcode( $atts ) {
      $atts['filter'] = do_shortcode( "[acf field={$atts['acf_field']}]" );
      return tablepress_get_table( $atts );
    }

    To use this, please use this Shortcode then:

    [table-acf id=3 acf_field=model_code filter_columns="5" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true /]
    

    Note how, instead of filter=..., there’s now a acf_field=model_code parameter to define where the filter term should come from.

    Regards,
    Tobias

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    Hi,

    That works perfect and displays the expected results for model code, thank you!

    One more question sorry with it not being in a standard shortcode, how do i expand on that?

    i.e. in the shortcode i could use this filter

    [table id=3 filter="FilterTerm1&&FilterTerm2" filter_columns="5-6" /]

    Can i change this function somehow to include additional search terms?

    These additional search terms are plain text, not from another acf field
    i.e. FilterTerm1 is the acf field value but FilterTerm2 will just be static text i input.

    Regards,
    Jamie

    • This reply was modified 3 years, 11 months ago by jdobbsy1987.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    good to hear that this helped!

    To expand this with a static filter term, you can simple change the line

    $atts['filter'] = do_shortcode( "[acf field={$atts['acf_field']}]" );
    

    to

    $atts['filter'] = do_shortcode( "[acf field={$atts['acf_field']}]" ) . ( '' !== $atts['filter'] ? "&&{$atts['filter']}" : '' );
    

    Then, you would a Shortcode like

    [table-acf id=3 filter="FilterTerm1" acf_field=model_code filter_columns="5" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true /]
    

    Filter term 1 would be taken from the filter parameter, and filter term 2 would be taken from the ACF field.

    Regards,
    Tobias

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    That has worked a treat, thank you so much.

    Your support has been amazing

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    Hello,
    Does this method also apply for the table ID?

    add_shortcode( 'table-acf', 'dino_table_acf_shortcode' );
    function dino_table_acf_shortcode( $atts ) {
      $atts['id'] = do_shortcode( "[acf field={$atts['acf_field']}]" );
      return tablepress_get_table( $atts );

    I assigned the table id value to ACF field
    [table acf_field=wd_chart_mm /]

    I get a return [table “” not found /]

    • This reply was modified 3 years, 11 months ago by jpn21.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, this should work exactly like that. Are you sure that

    [acf field=wd_chart_mm]
    

    properly returns the table ID (if that Shortcode is added to the page)?

    Regards,
    Tobias

    HI,
    Yes it is working great.

    Table ID returns properly using
    [table-acf acf_field=wd_chart /]

    Actually, displaying in double nesting (Toggle widget (mm/in) embedded in TAB widget (woocommerce single product)

    Using CVS import including mm/in then assigned filtered shortcodes to display corresponding rows for each Toggle section.
    mm
    [table-acf acf_field=wd_chart hide_rows=all show_rows=1-4 /]
    in
    [table-acf acf_field=wd_chart hide_rows=all show_rows=6-9 /]

    Very flexible plugin. thank you for your great support.

    Cheers,
    JP

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    awesome! That’s really great to see!

    Best wishes,
    Tobias
     
    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Thread Starter jdobbsy1987

    (@jdobbsy1987)

    Hi,

    Sorry to re-open this but wondered if you could help.

    The above solution worked however the structure of the site wasn’t ideal so I have changed it so the pages in question are now in a catalogue plugin.

    Since doing this though the table data doesn’t appear to be pulling through so suspect it is to do with the nested shortcodes again as this time, in order for the product catalogue page to display the information I needed to use the Elementor shortcode which meant another shortcode being nested.

    I tested this theory by installing the new 2.0 Dev plugin and displaying the table via the block and the table shows, making me think it is shortcode related.

    I am happy to try and switch to using the block editor for this however wondered if you had documentation on the 2.0 “Configuration parameters” as I need to be able to achieve the equivalent of this…

    [table-acf id=3 filter="Screen Repair" acf_field=model_code filter_columns="6-7" row_order=sort row_order_sort_column=G row_order_sort_direction=ASC filter_full_cell_match=true /]

    Is this possible in 2.0 using the block parameters, if yes, what is the format to enter them?

    It looks like it should be something like this

    filter="Screen Repair" acf_field="model_code" filter_columns="6-7" row_order="sort" row_order_sort_column="G" row_order_sort_direction="ASC" filter_full_cell_match="true"

    However it doesn’t appear to work, im not sure if its to do with the ACF/function above?

    Here is the test page with it on – https://wordpress-482191-2563283.cloudwaysapps.com/compare-repair/repair-comparison/samsung-s22-repair/

    I’d expect to only see 2 results

    • This reply was modified 3 years, 8 months ago by jdobbsy1987.
Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘ACF Value in TablePress Filter’ is closed to new replies.