Determining Buddypress Author (or any author) From Listings Page

This topic contains 9 replies, has 3 voices, and was last updated by  Paolo 9 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #61337

    paulpd0
    Expired Member
    Post count: 3

    I am currently trying to associate each listing with the author of that listing somehow. I’m using the buddypress integration with the buddypress login, so I was hoping that each listing would be associated with that buddypress login in some way, so that I could add additional fields to the listing page based on the account of the person who made that particular listing.

    I want to accomplish this code within the listing page, but I don’t have any idea how I would accomplish getting the author of the listing.

    
    
    $author = get_the_author();
    $vendor_user_login = get_userdata( $author );
    echo do_shortcode('[wcv_recent_products vendor="' . $vendor_user_login . '" per_page=3]');

    Any help or direction would be greatly appreciated, thank you!

    #61345

    Guust
    Moderator
    Post count: 29970

    Activate the Listings Claim addon, and then at GD > Listings Claims > Options tab > Show link to author page on listings? > YES.

    Let us know how you went.

    #61426

    paulpd0
    Expired Member
    Post count: 3

    Is there a way I can call on the author of the listing via Php? I installed the listings claim plugin and turned on the “show link to author page on listings” option but it made no change to the listings, still not seeing the author. Also, that isn’t exactly what I’m trying to do – I want to call on the author of the listing to then echo something from another plugin. This other plugin is using the buddypress login, also have geodirectory set to use buddypress login so I’m hoping that there will be a way to call on that author through php on the listing page.

    #61436

    Guust
    Moderator
    Post count: 29970

    You will see the author link there as soon you set the listing as “claimed” [edit the listing > Is claimed?].
    I’ll get Paolo to have a look at the rest of your question.

    #61494

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    you can display the author of a listing with the regular wordpress function:

    the_author();

    https://codex.wordpress.org/Function_Reference/the_author

    Buddypress or WordPress, this doesn’t change.

    Let us know how you went,

    Thanks

    #61496

    Paolo
    Site Admin
    Post count: 31211

    I’m sorry, I should have read the 1st question.

    get_userdata returns an object.

    https://codex.wordpress.org/Function_Reference/get_userdata

    Depending on what the shortcode needs as parameter and I assumed it needs : username.

    This should be something like:

    $vendor_user_login->user_login

    using just :

    $vendor_user_login

    Will return the whole object and your shortcode will not work.

    Let us know how you went,

    Thanks

    #61533

    paulpd0
    Expired Member
    Post count: 3

    Thank you so much for the help. The code still does not seem to work, I suppose I will need to speak with tech support from other plugin to fix that, but perhaps it is in the way I am trying to apply the code.

    If I wanted this code to be executed on each listing page, would I copy the listing.php file and create a Geodirectory folder in my theme, copy the file there and then place this Php code anywhere in there? Apologies for my lack of knowledge, any help is greatly appreciated!

    #61575

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    depending on where you want to add it, there are several hooks that can be used without copying templates in your child theme.

    For example you could create a new tab with it: https://wpgeodirectory.com/add-a-new-tab-in-the-listing-detail-page/

    Let us know how you went,

    Thanks

    #62776

    paulpd0
    Expired Member
    Post count: 3

    Paolo,

    I’m trying to use a shortcode within the new tab created in the link you gave me in previous post ^^

    The shortcode is not working

    This is what I’m trying to do

    
    
    
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    if($tab_index =='my_new_tab')
    {echo "[php snippet="1"][/php]";}
    }

    I have tried removing the quotes but it produces error, and with them the text of the shortcode is displayed. Plz help!

    #62864

    Paolo
    Site Admin
    Post count: 31211

    You can’t echo a shortcode with php. You must wrap the shortcode with a do_shortcode function.

    https://developer.wordpress.org/reference/functions/do_shortcode/

    CHeck the User Contributed Notes at the bottom of the page with examples.

    Thanks

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount