Support

Account

Home Forums General Issues Query posts based on user field

Solved

Query posts based on user field

  • Hi Elliot (or anyone else),

    I was wondering if there is a way of querying posts based on the user field?
    I’ve tried following example 3 on this page but not having any success.

    On the site, I have a custom post type for a staff section. On each staff post there is a user field so that the staff profile can be linked to a user account. That way on the site, on each staff members profile page there is a list of their recent posts at the bottom (this part is all working fine).

    What I’m looking to do now is to link each single post, back to the relevant staff profile page (if there is one), rather than using the usual the_author_posts_link(). I figure querying the staff posts and filtering to posts that have a staff-username value that matches the post author would be the neatest way of achieving that.

    Thanks in advance.

  • Hi @Nathan

    Example 3 on the linked page won’t work in this case, as the query should be quite simple.

    If I understand correctly, the ‘staff’ post type contains a user select field where 1 user is selected. Is this correct?

    If so, then example 1 is what you shoudl look at.
    The meta_value in this case is the ID of the user.

    Does that help?

    Thanks
    E

  • Hi @elliot. Perfect, that did the trick. Thanks very much for your help.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Query posts based on user field’ is closed to new replies.