This topic has 7 replies, 2 voices, and was last updated 9 years by bhavya.

  • Author
  • #53771
     bhavya
    Participant

    Hi,
    I want to use certain buddypress functionality while displaying the wordpress posts.
    Specifically – I am trying to use bp_displayed_user_id/$bp->displayed_user->id inside content.php (in my child theme). But bp_displayed_user_id returns 0 inside content.php
    Can you please let me know how i could do this?
    Thanks.

    #53775
     sharmstr
    Moderator

    have you declared

    global $bp;

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #53776
     sharmstr
    Moderator

    Wait. bp_displayed_user_id is for use within a profile. Basically its what user is being displayed. Do you need something like logged in user instead?

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #53778
     bhavya
    Participant

    Yes I have declared global $bp.
    Basically, I want to display buddypress follow button in the author meta.
    So I need both displayed user id & logged in user. And i want bp_displayed_user_id to be set correctly at this stage (to enable follow button) but it is not.
    I am able to use bp_loggedin_user_id to get the logged in user.

    #53780
     sharmstr
    Moderator

    You cant use bp_displayed_user_id to return the author id from a post because as I said before, you’re not in a buddypress profile.. You need to use https://codex.wordpress.org/Function_Reference/the_author_meta

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #53782
     bhavya
    Participant

    But I am able to use bp_displayed_user_id inside post-content-small.php which basically lists all the posts. That is why I am wondering if I am missing something while displaying the individual posts?
    Can I somehow extend buddypress profile to use in content.php?
    Thanks!

    PS: If i use the author meta i will have to make a lot of changes in my existing function so keeping it as a last resort.

    #53788
     sharmstr
    Moderator

    I dont understand why you’d have to make a bunch of changes. All you’re looking to get is the userid of the author. Once you have that, you can use it in any buddypress function call.

    So instead of $bp->displayed_user->id, use get_the_author_meta( ‘ID’ );

    If you look at the Kleo author meta functions, it uses get_the_author_meta( ‘ID’ ) to call buddypress functions as well. That’s because you cant use $bp->displayed_user->id to get the author id.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #53808
     bhavya
    Participant

    hmmm..Inside my function am actually using bp_displayed_user_id in some places to perform certain checks as to display the follow button or not & the same function is called from different places.
    Anyway, I will just work around that.
    Thanks for your help! 🙂

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

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?