[wp-hackers] get_post_meta in a widget

fris fris at fris.net
Tue Apr 17 06:00:59 UTC 2012

I been racking my head around this and cant seem to find a solution for
getting a custom field of a post, just returns empty.

	global $post;
	$args = array('numberposts' => $number, 'post_type' => 'bookmarks',
'orderby' => $sortby, 'order' => $order, 'meta_key' => 'bookmark-url');
	$myposts = get_posts( $args );
	foreach( $myposts as $post ) : setup_postdata($post); ?> 
	<?php global $wp_query; ?>
	<?php $url =
get_post_meta($wp_query->queried_object->ID,'bookmark-url',true); ?>
	<a href="<?php echo $url; ?>"><?php the_title(); ?></a>
	<?php endforeach; ?>

Here is the part of code where its not outputting the custom field for the
bookmarks post type

Also tried $post->ID for get_post_meta.

Anyone have any ideas?


More information about the wp-hackers mailing list