WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rough demo here to try and illustrate my problem.


I have six pages with titles - Page One, Two etc.

On a index/home page I'm creating a btn/div to link to each page.

On one of the btn's I want to put an extra label/mark.

On the page connected to that btn I have created a custom field with the name of label.

In the loop I am checking for this custom field with get_post_meta. If it's there I'm adding a to the div.

My problem is the is added to the other div's after the after the div/page that has the 'label' custom field.

In the example page http://www.ttmt.org.uk

I want the added label on Page Three but it also appearing on the after that.


        $frontAgrs = array(
            'post_type' => 'page',
            'tag' => 'group',
            'orderby' => 'menu_order',
            'order' => 'ASC'

        $frontLoop = new WP_Query($frontAgrs);


        if(get_post_meta($post->ID, 'label', true) != ''){
            $label = get_post_meta($post->ID, 'label', true);
            $label = '<em>'.$label.'</em>';

        $btnName = get_the_title();


    <?php echo '<div class="theDiv" ><a href="'.get_permalink($post->ID).'"><span>'.$btnName.'</span>'.$label.'</a></div>' ?>

    <?php endwhile; endif; ?>

    <?php wp_reset_postdata(); ?>           
share|improve this question
up vote 1 down vote accepted

You need to put an exception into your conditional:

if(get_post_meta($post->ID, 'label', true) != ''){
   $label = get_post_meta($post->ID, 'label', true);
   $label = '<em>'.$label.'</em>';
} else {
   $label = '':
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.