[wp-hackers] get_post_meta in a widget

Rafael Ehlers rafaehlers at gmail.com
Tue Apr 17 06:25:02 UTC 2012


Try only this:

$args = array('numberposts' => $number, 'post_type' => 'bookmarks',
'orderby' => $sortby, 'order' => $order, 'meta_key' => 'bookmark-url');
       $myposts = get_posts( $args );
       foreach( $myposts as $post ) : ?>
       <?php $url = get_post_meta($post->ID,'bookmark-url',true); ?>
***can't remember if ID or post_ID
       <a href="<?php echo $url; ?>"><?php $post->post_title; ?></a>
       <?php endforeach; ?>



On Tue, Apr 17, 2012 at 3:00 AM, fris <fris at fris.net> wrote:

> 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?
>
> Thx
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list