When I call get_post_custom in a loop, it works properly. But it prints 38 on my screen. Is it a wp bug or what? How can I fix it?
More Info:
It happens when I call get_post_meta as well. I am using custom field template plugin.
$args = array(
'post_type' => 'attendeeaddress',
'meta_query' => array(
array(
'key' => 'MEETING_ID',
'value' => $meeting_id,
'meta_compare' => '='
)
)
);
$wpquery = new WP_Query($args);
$addresses = array();
while ( $wpquery->have_posts() ) : $wpquery->the_post();
$custom_val = get_post_custom(the_ID());
$addresses[] = array(
"address" => $custom_val["MEETING_ADDRESS"][0],
"meeting_id" => $meeting_id,
"lat" => $custom_val["MEETING_LAT"][0],
"lon" => $custom_val["MEETING_LON"][0],
"name" => $custom_val["NAME"][0]
);
endwhile;
return $addresses;
It’s because the_ID(); actually “echoes” the value.
To just collect the value, use get_the_ID();
http://codex.wordpress.org/Function_Reference/the_ID
http://codex.wordpress.org/Function_Reference/get_the_ID