Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iamrealfarhanbd/d75110cdf85773d519228df7c72dfc5a to your computer and use it in GitHub Desktop.
Save iamrealfarhanbd/d75110cdf85773d519228df7c72dfc5a to your computer and use it in GitHub Desktop.

Documentation: Display Entries Submitted by Current User in Ninja Tables

This guide will help you display only the entries submitted by the current logged-in user using the Ninja Tables plugin in WordPress.

Steps to Achieve Current User Entries Display

1. Add User Information to Table Column

Ensure that the table includes a column with the user's name, email, or any user unique identifier.

2. Use Insert PHP Code Snippet Plugin

To filter the table based on the current user, you will need to use the Insert PHP Code Snippet plugin. This plugin allows you to add custom PHP code and generate a shortcode for it. Screenshot Link

3. Add the Following PHP Code

Add the following PHP code in the Insert PHP Code Snippet plugin to filter the Ninja Tables entries by the current user. After saving, the plugin will generate a shortcode that you can use in your pages.

PHP Code Example 1: Filter by Username

<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) {
    $getUsername = $current_user->user_login;
    echo do_shortcode('[ninja_tables id="Table ID Here" filter="' . $getUsername . '"]');
}
?>

PHP Code Example 2: Filter by Email

<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) {
    $getEmail = $current_user->user_email;
    echo do_shortcode('[ninja_tables id="499" filter="' . $getEmail . '"]');
}
?>

PHP Code Example 3: Specific User Role and Columns

This example shows how to display specific columns for users with a particular role (e.g., 'editor').

<?php global $current_user; wp_get_current_user(); ?>
<?php $user = wp_get_current_user();
if ( in_array( 'editor', (array) $user->roles ) ) {
    echo do_shortcode('[ninja_tables id="2926" columns="woo_product_image"]');
}
?>

4. Embed the Shortcode in Your Page

Copy the generated shortcode from the Insert PHP Code Snippet plugin and paste it into the desired page where you want to display the filtered table.

5. Video Demonstration

For detailed instructions, watch the demonstration video here: Video Link.

Conclusion

By following these steps, you can easily display entries submitted by the current user in Ninja Tables. Customize the PHP code snippets as needed to fit your specific requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment