Support » Plugin: Posts in Sidebar » How to display posts to certain user

  • Resolved rootstone


    Hi Aldo or other contributors,

    I have to say,

    “This is a great and powerful Widget!!”

    I have a special need to display certain posts for certain user. I already set a meta for those posts with a certain username. So my goal is to display these posts when this user logs in, not other posts.

    I read all the docs you provided but I don’t know much about coding and really need your help to understand or get the codes for it.

    I read the link of “wp-query” you provided and know there is a query to get user ID:

    Line 2430: $user_id = get_current_user_id();

    So my request is:

    Could you help me with a shortcode (please tell me where to put it) that will query the user id for logged in user (this widget is for logged-in users) and display the posts with the meta info which I set with the logged-in user ID.

    Many many many thanks for helping me!

    • This topic was modified 1 month ago by rootstone.
Viewing 13 replies - 1 through 13 (of 13 total)
  • rootstone



    I tried this shortcode:
    [pissc cat=”sponsorship” tag=”get_current_user_id()”]

    But it shows in the sidebar saying: No posts yet.

    Should I register the “$user_id = get_current_user_id();” first in Posts in Sidebar before I put the shortcode in the Custom HTML in the sidebar? I don’t know how to use the shortcodes/set the settings…

    Thanks for your help!

    Plugin Author Aldo


    Hi @rootstone,

    I have to say,

    β€œThis is a great and powerful Widget!!”

    Thank you! πŸ™‚

    Regarding your request, do you want to show a particular widget to a particular user? I mean, do you have only one particular user? Because, if you have – let’s say – 100 users and you want to display a custom sidebar widget to 100 users, my advice is not applicable.

    Let me know.



    Thank you for your prompt reply!

    Yes, I have quite many users. My goal is to show different user one or more pages/posts that others can’t see.

    My idea is that:
    1. I will add the userid or username of this user as a tag or other items like meta value or keys to one or more posts first.

    2. Then I will put this “Posts in Sidebar” on the right side, and when a user logs in, it will check the user’s ID or username and then pull those posts according to the logged-in user’s ID or username, and display them when they log in.

    The key here I think is if this plugin can add one more function to check current user’s id and then make the “get” action.

    If you can make it happen, it will beat a loooooot of content Restrict plugins, like WP Private Content Plus, etc.


    Plugin Author Aldo


    I will check if what you’re asking is possible, I promise. πŸ™‚
    I’ll let you know as soon as possible.

    Plugin Author Aldo


    I did it! πŸ™‚
    It’s in an early stage… but it works.

    Each user sees the posts that have his username (login name), while non-logged-in users see a standard posts list.




    You ARE AWESOME!!!

    Thumb UPPPP!

    How can I use it?

    Plugin Author Aldo


    Hello @rootstone,
    I just released the new version 4.10.0. Simply, update the plugin and you’ll have the new option available.

    Go to the widget admin and find the new panel here:
    “Getting posts” > “Get posts from username”

    Activate the option “Get posts from current username” and you should be done.

    In the front-end, the widget will show posts that have a meta key equal to the username of the currently logged-in user (the logged-in user that is visiting your site).

    You can use the new option in the shortcode too. For example:

    [pissc number=3 get_from_username=1 ignore_sticky=1]


    number=3 is the number of posts you want to show;
    get_from_username=1 activate the option to get posts from username;
    ignore_sticky=1 do not show sticky posts on top of other posts.

    Please, let me know if it works as expected.

    Thank you so much Aldo!!

    I already updated it to 4.10.1, but I have a trouble to find the custom fields from the “Screen options” list which I am contacting the DIVI support for answers. After that, I will try it —- I am so excited to see it happen!!!

    Will update it as soon as I solve the “custom fields” issue.

    Plugin Author Aldo


    Ok, let me know, please! πŸ™‚

    Awesome!!! It works like a charm!!!

    Really appreciate your work and efforts to help me!!

    Plugin Author Aldo


    Great!! Thank you for your feedback! πŸ™‚

    Hello. Just a quick question. Inline with the above updated can the plugin be modified to show also private posts for the user that is logged in and if the user is the author?

    So is there a possibility for you to add the below?

    [] Display private posts for current username

    Plugin Author Aldo


    I will take a look into this. There is already the option to get posts from current username, and I don’t want to create confusion in users. Anyway, stay tuned. πŸ™‚

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