1

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 1

1

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: ?>
2
  • 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?
    – Mike
    Commented 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.
    – Wyck
    Commented Mar 17, 2011 at 4:53

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.