0

As geo mashup only retrieves post_meta, I am trying to copy over the geo_location from a custom registration field into the meta for page containing the map.

The code I am using is:

<?php 
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
$user_location = the_author_meta('geo_address', $user->ID);
 add_post_meta( 463, 'geo_move', $user_location); 

}}
?>

This creates the post meta, but the value is written as a blank, so it looks like $user_location isn't working. Any suggestions?

1 Answer 1

1

First of all get_users_of_blog has been deprecated, so you should use get_users instead, or run a WP_User_Query.

After that, the_author_meta echo the meta value, not return anything. To return the meta you should use get_the_author_meta()

$blogusers = get_users( $args ); // for args see codex

if ($blogusers) {
  foreach ( $blogusers as $bloguser ) {
    $user_location = get_the_author_meta('geo_address', $bloguser->ID );
    $has_meta = get_post_meta(463, 'geo_move', true);
    if ($user_location && ! $has_meta) add_post_meta( 463, 'geo_move', $user_location);
  }
}
3
  • And that's done it! A supplemental query - if I add this as a function, will it duplicate the fields every time the site is refreshed? I'm testing it in a page template and every refresh duplicates the content
    – Paul Aston
    Nov 8, 2013 at 19:22
  • @PaulAston I've edited the answer to prevent duplicates.
    – gmazzap
    Nov 8, 2013 at 19:48
  • Above and beyond! That's great!
    – Paul Aston
    Nov 8, 2013 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.