This guide will help you display only the entries submitted by the current logged-in user using the Ninja Tables plugin in WordPress.
Ensure that the table includes a column with the user's name, email, or any user unique identifier.
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
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 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 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 . '"]');
}
?>
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"]');
}
?>
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.
For detailed instructions, watch the demonstration video here: Video Link.
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.