Support » Plugin: TablePress » Use user login system tag in filter shortcode

  • Resolved formfunia

    (@formfunia)


    i am using tablepress and in filter shortcode of tablepress is it possible that filter word automatic replace with login user.

    For example=
    [table id=1 filter=”[user_login]”]

    so if let rohit is user name then shortcode should automatically become [table id=1 filter=”rohit”]

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

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    The best way for that should be to develop a small plugin that adds a wrapper around this Shortcode. For inspiration, please see https://wordpress.org/support/topic/pre-filter-table-based-on-user-profile-value/
    This pretty much contains the solution, you will just need to replace

    $wpuef_result = wpuef_get_field('c2', $userid);
    $filter = var_dump($wpuef_result->value);
    $atts['filter'] = $filter;

    with

    $atts['filter'] = $userid;
    

    Regards,
    Tobias

    I am a new learner of wordpress.And i did what i can understand by your reply.But stuff didn’t work as expected.So can you please tell me what exactly have to enter in function.php and what shortcode should use so that filter word change to logged in user automatically.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    add this to your theme’s “functions.php” file:

    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 );
    }

    Then, you can use the Shortcode

    [table-user-filtered id=1 /]
    

    (with the correct ID) and it will automatically only show the rows that match the current user’s username.

    Regards,
    Tobias

    Hey I have did it.
    I just Change the “ID” with “User_login” and then the stuff starts working as expected.
    Thank You for your caring support and incredible plugin.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

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

    Best wishes,
    Tobias

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

    hey tobias,
    actually i want that table show only that columns which have exactly same word as user name.

    For example , let “tobias” is a user name.
    then table should show only that columns which have only tobias not tobiasBG or TobiasJohn etc.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    for that, also add the line of code

    $atts['filter_full_cell_match'] = true;
    

    Regards,
    Tobias

    It works!!!
    Thanks Tobias

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    Good to hear that this helped!

    Best wishes,
    Tobias

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

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Use user login system tag in filter shortcode’ is closed to new replies.