• Resolved typofi

    (@typofi)


    Hello. First of all, thanks for the great plugin!

    I’ve been trying to get this to work so that the current user info (user id or login name) would be passed on as a category to the query. I kind of got it to work but not really. I haven’t quite got the skills.

    Something like, first query the current user:

    $current_user = wp_get_current_user();
    $got_login_name = $current_user->user_login;

    Then result $got_login_name would be passed on as a category name to your query.

    So “user1” would see posts categorized “user1”.

    Or maybe there’s a much better way to get personalized posts listed per user, but this is as far I’ve got now. So the user is not the author here. They are simply posts that the admin has dedicated to this user. And categories seem to offer a simple and fast way to handle the dedication process. (I suppose the same could be done with a custom field too.)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    Display Posts already lets you query for the current user’s posts. It does it based on post author, not a category.

    Try this: [display-posts author=”current”]

    Thread Starter typofi

    (@typofi)

    Hi, thanks for the reply but you missed the bit where I tried to tell that in this case the user is not the author. That’s the whole point of what I am trying to do.

    I’m not displaying the author’s posts to the author. That would be simple. I want to display a certain set of posts to the user by using a category, regardless of who the author is.

    So the easiest way to do this, as far as I can see is to have a category that is the same as the user name. Then I just need to query the user name and feed that into Display Posts as an attribute.

    • This reply was modified 4 years, 7 months ago by typofi.
    Plugin Author Bill Erickson

    (@billerickson)

    Try adding this to your theme’s functions.php file or a core functionality plugin: https://gist.github.com/billerickson/58e50a14c596c2fa4268a6e3bda49667

    Thread Starter typofi

    (@typofi)

    Thank you! Works perfectly!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query based on current username’ is closed to new replies.