Support » Plugin: TablePress » Filter by username

  • Resolved jnmcabee

    (@jnmcabee)


    Tobias,

    Love the plugin man, but I need your help. I’m posting tables with hundreds of rows and 6 columns. One of the columns is the user’s username on the site. I need to make it so the Tablepress table filters the table and ONLY shows that user’s row (so it needs to match the logged in user’s username and filter out everything EXCEPT the row that contains the username).

    Is this possible?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    Why are you not trying the suggestion that I made to your exact same question about a year ago? 🙂
    See https://wordpress.org/support/topic/filter-by-username/

    Regards,
    Tobias

    jnmcabee

    (@jnmcabee)

    Hi Tobias,

    Sorry for not following up on that post from a year ago! But when I try that, I get a Fatal error.

    Do you think you’d be able to take a look at that?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    then we should try to fix that error 🙂

    What’s the exact code that you have tried, where exactly did you add it, and what is the full error message that your getting?

    Regards,
    Tobias

    jnmcabee

    (@jnmcabee)

    Tobias,

    I’m getting the error when I try to edit the post or page that the [table-user-filtered id=x /] is on

    I entered this code in the functions.php of the theme

    add_shortcode( ‘table-user-filtered’, ‘formfunia_tablepress_filtered_table’ );
    function formfunia_tablepress_filtered_table( $atts ) {
    if ( ! is_user_logged_in() ) {
    return ‘Error: No user is logged in.’;
    }
    $current_user = wp_get_current_user();
    $username = $current_user->user_login;
    $atts[‘filter’] = $username;
    $atts[‘cache_table_output’] = false;
    return tablepress_get_table( $atts );
    }

    And here’s the full error:

    Fatal error: Uncaught Error: Call to undefined function tablepress_get_table() in /nas/content/staging/fantasyracing/wp-content/themes/Newspaper/functions.php:128 Stack trace: #0 [internal function]: formfunia_tablepress_filtered_table(Array, ”, ‘table-user-filt…’) #1 /nas/content/staging/fantasyracing/wp-includes/shortcodes.php(319): uopz_call_user_func(‘formfunia_table…’, Array, ”, ‘table-user-filt…’) #2 [internal function]: do_shortcode_tag(Array) #3 /nas/content/staging/fantasyracing/wp-includes/shortcodes.php(197): preg_replace_callback(‘/\\[(\\[?)(table\\…’, ‘do_shortcode_ta…’, ‘[table-user-fil…’) #4 [internal function]: do_shortcode(‘[table-user-fil…’) #5 /nas/content/staging/fantasyracing/wp-includes/class-wp-hook.php(286): call_user_func_array(‘do_shortcode’, Array) #6 /nas/content/staging/fantasyracing/wp-includes/plugin.php(203): WP_Hook->apply_filters(‘[table-user-fil…’, Array) #7 /nas/content/staging/fantasyracing/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1520): apply in /nas/content/staging/fantasyracing/wp-content/themes/Newspaper/functions.php on line 128

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for that information! Now I see what’s going on. To fix this, we need to slightly modify the code. Please try again with

    if ( ! is_admin() ) {
      add_shortcode( 'table-user-filtered', 'formfunia_tablepress_filtered_table' );
      function formfunia_tablepress_filtered_table( $atts ) {
        if ( ! is_user_logged_in() ) {
          return 'Error: No user is logged in.';
        }
        $current_user = wp_get_current_user();
        $username = $current_user->user_login;
        $atts['filter'] = $username;
        $atts['cache_table_output'] = false;
        return tablepress_get_table( $atts );
      }
    }

    Regards,
    Tobias

    jnmcabee

    (@jnmcabee)

    YOU ARE THE BEST! That works perfectly.

    Thank you. Where can I donate?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!
    And thanks for wanting to donate, please see https://tablepress.org/donate/ for that.

    Best wishes,
    Tobias

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

    jnmcabee

    (@jnmcabee)

    Tobias,

    Small issue found. Okay so I have two tables in the page, one using the table-user-filtered and that’s working fine, but it’s causing the other table JavaScript features to not work. I have Sorting, Search/Filtering, Pagination, etc. checked on, but they’re not working with the table that doesn’t have the table-user-filtered

    Can this be fixed?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    I don’t think that this is caused by the filtered table, but has other causes. Can you please post a link to the page with the table where this problem happens, so that I can take a direct look? Thanks!

    Regards,
    Tobias

    jnmcabee

    (@jnmcabee)

    It works fine when a user isn’t logged in and the [table-user-filtered] says “Error: No user logged in” .. but once a user is logged in then it’s not working for the second table as mentioned above.

    So I need to create you an account on the site I think and have you log in. How can I privately send that to you?

    https://fantasyracingonline.com/fantasy-nascar/slingshot-fantasy-auto-contest/private-leagues-members/

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok. Does the filtered table still contain the header row and at least one body row? And does it maybe contain #colspan# or #rowspan# for merged cells?

    If that’s not it, can you please email me the details, the address is in the main plugin file “tablepress.php”.

    Regards,
    Tobias

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.