454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Having a slight problem echo’ing some data in WP and need a slight nudge in the right direction

I am listing recent pages (using wp_list_comments) on another page outside of the loop, and need to grab the user data (for their profile).

I have the following:

echo the_author_meta( 'location' );

Which displays the Location field from the profile, but I need to add the user_id to the query which would be:

echo the_author_meta( 'location', 25 );

However I am generating the user ID using user_id() so need to do the following:

echo the_author_meta( 'location', user_id() );

Which gives the usual syntax errors

What is the best way of doing this?

525 posts Fuel Your Web
  • Elite Author
  • Won a Competition
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Europe
Pirenko says

What are the usual syntax errors? Paste them here…

951 posts How's the surf doing?
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 2-3 years
  • Microlancer Beta Tester
+1 more
tommusrhodus says

There’s every chance I’m wrong here, but wouldn’t it best to assign user_id(); to a variable first and then call that variable in place within the_author_meta(); function?

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Thanks Tommus

Nearly there but still not showing the field

foreach($comments as $comment) { ?>
 <?php $user = $comment->user_id ?>
 Location: <?php echo the_author_meta( 'location', $user ); ?>

No errors anymore but not showing the field! Any ideas?

951 posts How's the surf doing?
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 2-3 years
  • Microlancer Beta Tester
+1 more
tommusrhodus says

Again this is just guess work, but this line:

 <?php $user = $comment->user_id ?> 

Would this work?

 <?php $user = $comment->user_id(); ?> 
by
by
by
by
by
by