• Resolved rootstone

    (@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!
    Stone

    • This topic was modified 5 years ago by rootstone.
Viewing 15 replies - 1 through 15 (of 29 total)
  • Thread Starter rootstone

    (@rootstone)

    Update:

    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!
    Stone

    Plugin Author Aldo Latino

    (@aldolat)

    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.

    Thread Starter rootstone

    (@rootstone)

    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.

    Thanks!~!

    Plugin Author Aldo Latino

    (@aldolat)

    I will check if what you’re asking is possible, I promise. ??
    I’ll let you know as soon as possible.

    Plugin Author Aldo Latino

    (@aldolat)

    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.

    Thread Starter rootstone

    (@rootstone)

    Wow~~~

    You ARE AWESOME!!!

    Thumb UPPPP!

    How can I use it?
    Stone

    Plugin Author Aldo Latino

    (@aldolat)

    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]

    where:

    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.

    Thread Starter rootstone

    (@rootstone)

    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 Latino

    (@aldolat)

    Ok, let me know, please! ??

    Thread Starter rootstone

    (@rootstone)

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

    Really appreciate your work and efforts to help me!!

    Plugin Author Aldo Latino

    (@aldolat)

    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 Latino

    (@aldolat)

    @gamark
    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. ??

    Hi, nice plugin you have here. I got it with intention of showing each author his or latest published post. I have ticked the option “get posts from current username” However, its showing all authors the latest published post – not the one the author has written. Where am i going wrong? or maybe i’ve misunderstood its use

    Plugin Author Aldo Latino

    (@aldolat)

    Hi @searchngp
    That function was created to show posts that have a meta key equal to the current logged-in user.

    In other words, if a user is logged in, that option will show posts that have his username as meta key, if present, and will show those posts, otherwise will simply show posts from according to the other options.

    This function is explained in the panel Get posts from username”.

    For example, let’s say that John Doe is currently navigating the site and his username is johndoe. The widget will show him the posts that have a johndoe meta key. To achieve this, the administrator (or who can edit posts) must previously mark the posts with this meta key.

    Please, let me know if you need further assistance.

    P.S.
    Another user, namely @gamark, asked me to add a feature similar to the one you would like to have in this plugin. As soon as I can, I will see if this feature can be added. ??

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘How to display posts to certain user’ is closed to new replies.