Support Forum

get user id

CA Carlos
Carlos
Member

Hi! i want to show a extra html info on the profile… the main code on any wp page is:

<?php echo userpro_show_badges( $user_id, $inline=false ); ?>

 

I trying to implement it on the  topicview.php but I´m having problems getting the user id of the post…

 

this is the code i´m using

echo '<div class="spPostUserLocation spCenter">';
echo userpro_show_badges( $user_id, $inline=false );
echo '</div>';

but no luck getting the user id….

 

I have been reading and some users are adding something like:

 

$user_id = get_the_author_meta(‘ID’);

Can anyone bring me help with this? 

 

 

 

9 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

If you are referring to putting your code within the forum post ‘loop’ then the ID of the current author of the individual post can be obtained from:

$spThisPostUser->ID

Functions like get_the_author_meta() are strictly WP and refer to WP ‘posts’.

CA Carlos
Carlos
Member

and that code will retrieve de wp user id?

 

how must i integrate it?

YS Yellow Swordfish
Yellow Swordfish
Member

If it is used in the within ‘post loop’ on the spTopicView.php theme template then yes – it returns the ID of the current post author being displayed.

Not sure what you mean by ‘integrate it’. It returns the users ID. What you have in your function above as $user_id

TL Trevor Lyman
Trevor Lyman
Member

I’m looking to do this, but I want to key off of the user that initiated the post only.  So if user 15 starts a post I want certain things to happen based on that and only that. 

Do I get a different type of userID for this?  Is there a “post starter ID” or anything like that that I can key off of?

MP Mr Papa
Mr Papa
Member

You haven’t mentioned where you want to do this… It may vary…

Take a look at forum – toolbox – data inspector where you can display available global data based on page view…

User ID is available just need more specifics….

TL Trevor Lyman
Trevor Lyman
Member

Mr Papa said
You haven’t mentioned where you want to do this… It may vary…

Take a look at forum – toolbox – data inspector where you can display available global data based on page view…

User ID is available just need more specifics….

So basically I want to key off of the user that started the forum thread and do revenue share with them.

I’m going to be looking at this page to insert banner ads into the forum content section: https://simple-press.com/support-forum/sp5-coding-questions/adsense-code/page-4/

And if a user who i am doing rev share with starts the post, I want to create some code that is going to key of of their user ID and then include their ad code in the banners that are shown in the pages for the thread.

Does this make sense?

I don’t think I need to use the data inspector (and don’t know how) at this point?

MP Mr Papa
Mr Papa
Member

still not sure what you want to do…  and why you didnt try the data inspector – very simple point and click and then displays globally available data on the page to you, including various user ids (logged in, current post, etc)…

you seem to be mentioning two different users in your discussion… the user who started the topic and the user adding a post…

and the topic you linked to referred to adding a banner at top… so if on fifth page of a topic, do you still only want access to the user id of the topic starter, which is currently not visible since you are on page 5?  on will you always ONLY be on topic view??

If all you want to do on any topic view page is grab the user id of the person who started the topic, you can get at it via:

$spThisTopic->topic_starter

if other, please explain in more detail what you want to accomplish…