WordPress.org

Ready to get started?Download WordPress

Forums

query_posts by author (8 posts)

  1. yan.odnoralov
    Member
    Posted 2 years ago #

    Hi, I'm using buddypress and in a custom user tab I’m trying to display that users posts. (displayed user, not logged in user).

    I wrote this query and by my understanding it's correct but it’s not working for me. It should pull the ‘displayed users’ posts only, instead it shows all posts. How Can I make it pull only posts by the “displayed user”? By Buddypress Codex "$bp->displayed_user->id" would be the variable.

    query_posts( 'author=' . $bp->displayed_user->id );
    
    // the Loop
    while (have_posts()) : the_post();
    	the_content( 'Read the full post »' );
    endwhile;

    What am I doing wrong?

    Thanks a ton!

    [No bumping. If it's that urgent, consider hiring someone.]

  2. egado
    Member
    Posted 2 years ago #

    Hm... I have never used buddypress, but are you sure, that a buddypress user has theme ID in buddypress like the wordpress dashboard user?

    e.g. Maybe Simon O. Connor has the buddypress user ID 4 and the wordpress user/author ID 12 ...

  3. yan.odnoralov
    Member
    Posted 2 years ago #

    In my understanding buddypress theme does have its own user ids.

    But suppose it doesn't, can I just use wp user id to pull that users post? The complication is I'm not pulling by the logged in user, rather by the user who's profile I am on.

    e.g. I'm logged in as John, and I navigate to Simon's profile page (a fellow member of the site), I need to see Simon's post not John's.

    Any ideas?

  4. egado
    Member
    Posted 2 years ago #

    Ok, thats should be the reason why this query_posts( 'author=' . $bp->displayed_user->id ); shows all posts...

    I have no really good idea, how you can get the right user id, I mean the ID of Simon as a user/author of your site. Maybe... if the usernames are exactly the same like "Simon D." in your wordpress dashboard and "Simon D." in buddypress... you can query the post with his name instead of the ID?

    don't know if it right, but this shows what I'am trying to say (sorry for my english) :)

    query_posts( 'author=' . $bp->displayed_user->name );

    or

    query_posts( 'author=' . $bp->displayed_user->slug);
  5. yan.odnoralov
    Member
    Posted 2 years ago #

    Hmmmm... So I gave this a shot: `query_posts( 'author=' . $bp->displayed_user->slug );

    // the Loop
    if (have_posts()) : the_post();
    the_content( 'Read the full post »' );
    echo bp_member_permalink();

    endif;
    `
    But still no luck... Do I need to have "displayed_user->slug" as global function inside y functions.php? If so, do you know how I would code that?

  6. egado
    Member
    Posted 2 years ago #

    Seems that buddypress has that as a build in variable...

    $bp->displayed_user->fullname

    Source: http://codex.buddypress.org/developer-docs/the-bp-global/

    So your User/Author should have the same "Fullname" in your wordpress dashboard as in buddypress $bp->displayed_user->fullname

    No other ideas at the moment :( Is there anybody out there with more experience on buddypress? :)

  7. yan.odnoralov
    Member
    Posted 2 years ago #

    Your right. But I found another way :)

    w/ global:

    function my_profile_page_function_to_show_screen333_content() {
    global $bp;
    
    query_posts( 'author=' . $bp->displayed_user->id );
    
    // the Loop
    if (have_posts()) : the_post();
    	the_content( 'Read the full post »' );
    endif;
    }

    or more simple code that works as well:

    function my_profile_page_function_to_show_screen333_content() {
    query_posts( 'author=' . bp_displayed_user_id() );
    
    // the Loop
    if (have_posts()) : the_post();
    	the_content( 'Read the full post »' );
    endif;
    }
  8. egado
    Member
    Posted 2 years ago #

    Congrats :)
    So why do you ask us for help :-P </kidding>

Topic Closed

This topic has been closed to new replies.

About this Topic