How can I pull a custom field with meta_key "proprty_feature" (and has a value) for all posts and display them on my frontpage? Would like to display the post name as a link above the value..
1 Answer
Within your main post loop you would add something like,
get_post_meta($post->ID, 'property_feature', true);
A basic example of what your main loop might look like ( it depends on your theme) to include a title and your custom field.
//start the loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
//add post link and title
<a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
//add your custom meta value
<?php echo get_post_meta($post->ID, 'property_feature', true) ?>
//close loop
<?php endwhile; else: ?>
-
I apologize..I'm not sure if I'm following you..this will display a list of posts along with a corresponding custom field? So I can just put this in index.php?– MikeCommented Mar 17, 2011 at 3:06
-
Yes but I provided the example only to show you where it fits in. The loop example is extremely basic and very likely your theme has more styling and options. The important bit of code you need is the get_post_meta which as it sounds gets your post meta box based in name or key and returns the value.– WyckCommented Mar 17, 2011 at 4:53