Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Using bp displayed user to query posts

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @robparker,

    May I ask why you’re querying by username and not by user ID?

    You can simply use the author parameter with WP_Query. Using what you linked to as an example:

    $args = array(
        'posts_per_page' => 10,
        'paged' => $paged,
        'ignore_sticky_posts' => 1,
        'author' => $user_id
    );
    $query = new WP_Query( $args );

    Where $user_id will be bp_displayed_user_id() if you’re doing this query on a member’s profile page. Else, it’ll be something else depending on the context in which you’re using WP_Query.


    shanebp
    Moderator

    @shanebp

    I can guess why author may != the meta value, but it would be a lot easier if you stored the user id in that meta value field.

    Anyhow, you could use get_user.
    $person = get_user_by('id', bp_displayed_user_id());

    then

    ...
    'meta_value' =>  $person->user_login
    ...

    robparker
    Participant

    @robparker

    Thank you both

    The tricky thing about this site (and the bit I wasn’t involved in building) is that the username saved is not the post author, its just a custom field.

    However, the suggestion from @shanebp solves the problem – thank you very much.

    And thank you again to @henrywright – I think you’ve actually answered the next problem I was moving on to look at, where a second post type is set-up by author.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Using bp displayed user to query posts’ is closed to new replies.
Skip to toolbar