• Resolved tapsa1958

    (@tapsa1958)


    Hi,

    Thank you for this amazing plugin.

    How can I use the “Change the [table] Shortcode” plugin with the “Row Filtering from URL parameter” plugin.

    I would like to use this kind of url to filter: site.com/?mysite_filter=Keyword or site.com/?search=Keyword

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Here, you don’t need the “Change the [table] Shortcode” Extension, but you will need to make a modification to a PHP file instead: In particular, you will need to modify lines 17 and 18 of the file /wp-content/tablepress-shortcode-filter-get-parameter/tablepress-shortcode-filter-get-parameter.php from

    if ( ! empty( $_GET['table_filter'] ) ) {
    $filter_term = $_GET['table_filter'];

    to

    if ( ! empty( $_GET['search'] ) ) {
    $filter_term = $_GET['search'];

    Regards,
    Tobias

    Thread Starter tapsa1958

    (@tapsa1958)

    Excellent. Worked perfectly. Thank you very much.

    Is it possible to choose the table using url parameter?
    For example site.com/?search=Keyword&table_id=33 would use table 33 and show cells with word “Keyword”.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    good to hear that this worked! Yes, in principle, this would work. You would e.g. have to add a block like

    if ( ! empty( $_GET['table_id'] ) ) {
    	$table_id = (string) $_GET['table_id'];
    	// Only allow tables from this list.
    	$allowed_table_ids = array( '33', '34', '37', );
    	if ( in_array( $table_id, $allowed_table_ids, true ) {
    		$attributes['id'] = $table_id;
    	}
    }

    to the code. This contains a white list of allowed tables for this filtering, to prevent that someone can read all your tables (which might be undesired).

    Regards,
    Tobias

    Thread Starter tapsa1958

    (@tapsa1958)

    Thank you!
    I tried to add the code but it gives this error for the line 6:
    syntax error, unexpected ‘;’

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, sorry, there’s a ) missing. Please change

    if ( in_array( $table_id, $allowed_table_ids, true ) {
    

    to

    if ( in_array( $table_id, $allowed_table_ids, true ) ) {
    

    Make sure to add this right before the line

    return tablepress_get_table( $attributes );
    

    Regards,
    Tobias

    Thread Starter tapsa1958

    (@tapsa1958)

    I have added the code to the “Row Filtering from URL parameter” plugin. But it does not work..

    What shortcode should I use in the page?
    When I use [table_filter /] or [table_filter filter_full_cell_match=true id=”” /] the page says [table “” not found /]
    When I use [table_filter id=31 /] the page shows the table 31

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    you would then only need

    [table_filter /]
    

    (or

    [table_filter filter_full_cell_match=true /]
    

    if you want full cell matching).

    However, you must first fill that list of allowed tables. For example, ID 31 that you are using is not my original code. You should use that list in order to prevent that someone accesses an arbitrary table.

    Regards,
    Tobias

    Thread Starter tapsa1958

    (@tapsa1958)

    Excellent. Now it works perfectly!

    Is it posible to hide the text “[table “” not found /]” when the id is incorrect?

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes! For that, replace

    if ( in_array( $table_id, $allowed_table_ids, true ) {
    	$attributes['id'] = $table_id;
    }

    with

    if ( in_array( $table_id, $allowed_table_ids, true ) {
    	$attributes['id'] = $table_id;
    } else {
    	return 'There was an error.';
    }

    You can of course adjust this message as desired, or remove it by only using

    return '';
    

    Regards,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Change the [table] Shortcode for URL filtering’ is closed to new replies.