Title: Using custom fields to display specific posts
Last modified: August 19, 2016

---

# Using custom fields to display specific posts

 *  [jennymckenzie](https://wordpress.org/support/users/jennymckenzie/)
 * (@jennymckenzie)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-custom-fields-to-display-specific-posts/)
 * I am trying to create a ‘featured post’ section where anchored at the top of 
   the homepage, 3 articles are displayed (thumbnail icon is displayed)
 * In my post I have created a custom field called ‘post-icon’ and given it a value
   of a an image url.
 * I have the below code – which is great for showing the 3 most recent articles,
   but what I want to do is:
 * 1. check to see if the article has the post-icon custom field and a value for
   it.
    2. if so, display it in the featured section. If not, don’t display it.
 *     ```
       <?php query_posts('showposts=3&offset=0'); ?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
       	<img src="<?php echo get_post_meta($post->ID, 'post-icon', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
       </a>
       <?php endwhile; endif; ?>
       ```
   
 * I’ve tried a number of things but I can’t figure out how to do this.
 * Any ideas?

Viewing 1 replies (of 1 total)

 *  Thread Starter [jennymckenzie](https://wordpress.org/support/users/jennymckenzie/)
 * (@jennymckenzie)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-custom-fields-to-display-specific-posts/#post-1822317)
 * Follow up to the above post –
 * I figured out that if I add &meta_key=post-icon to the query_posts() so that 
   the code reads like this:
 *     ```
       <?php query_posts('showposts=3&offset=0&meta_key=post-icon'); ?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
       	<img src="<?php echo get_post_meta($post->ID, 'post-icon', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
       </a>
       <?php endwhile; endif; ?>
       ```
   
 * It does the trick – for the featured section. But it also carries on into the
   main loop… so that only these three articles show up at all.
 * How do I get ALL articles to display in the main loop and only the desiginated(
   by custom field) ones show up in the sidebar?

Viewing 1 replies (of 1 total)

The topic ‘Using custom fields to display specific posts’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * 1 reply
 * 1 participant
 * Last reply from: [jennymckenzie](https://wordpress.org/support/users/jennymckenzie/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/using-custom-fields-to-display-specific-posts/#post-1822317)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
