• Hey,

    I’m trying to exclude the custom field ‘Image’ from displaying on all single posts. I have four or five other meta keys and just need to stop the post image from displaying.

    I have seen some things around about how to do this, but they were fairly confusing. This one for example was the closest I got to a conclusive answer. But as you’ll see from my attempt at implementation, it did not end well.

    Any help appreciated,
    Marc

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not sure where you are putting that code but it should be inside your loop in your single.php. This worked fine for me:

    <?php
    if ( $keys = get_post_custom_keys() ) {
      echo "\n";
      foreach ( (array) $keys as $key ) {
        $keyt = trim($key);
        if ( '_' == $keyt{0} || 'Image' == $keyt )
          continue;
        $values = array_map('trim', get_post_custom_values($key));
        $value = implode($values,', ');
        echo apply_filters('the_meta_key', " $key: $value\n", $key, $value);
      }
      echo "\n";
    }
    ?>

    Related:
    Custom Fields
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    Thread Starter themarcthomas

    (@themarcthomas)

    Oh! That worked. My problem was an issue with how I was writing the Loop.

    Thanks for your help. Wondering if someone might be able to help me with two more mini questions:

    1. How do I control the order that the fields display in?
    2. How can I display each custom field on a new line?

    Any help would be greatly appreciated!
    Marc

    1. can’t find it right now, but I’m pretty sure I saw a method to do that somewhere in the forums in the last month or so
    2. could put echo "\n"; after this echo apply_filters('the_meta_key', " $key: $value\n", $key, $value);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude individual custom fields from single’ is closed to new replies.