• Hi,

    I know I can call custom fields one by one on a template. But is there a way for me to get all custom fields except one (or some).

    I’ve checked the codex pages on WordPress and there was no solution for that there.

    Thanks in advance for any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m guessing you missed this page then.
    http://codex.wordpress.org/Function_Reference/get_post_custom

    😉

    Thread Starter albertpr9

    (@albertpr9)

    <?php
    
      $custom_fields = get_post_custom(72);
      $my_custom_field = $custom_fields['my_custom_field'];
      foreach ( $my_custom_field as $key => $value )
        echo $key . " => " . $value . "<br />";
    
    ?>

    Ok. So I type my custom field in place of “my_custom_field” and use $post->ID; instead of the post number, to get the proper post ID inside the loop..

    It worked for me to get all values from one custom field separately.

    What I want to do is get all values from all custom fields, except specific custom fields. Example;

    <?php the_meta(); ?>

    That will give me all custom key values, but I would like it not to fetch key_5 for example.

    Cheers

    Can you be a little clearer about what it is that the function above is not doing for you?..

    As far as i can make out, you just need to exclude a particular key.. is that right? Or an i misunderstanding?

    I think what you want is two nested loops:

    <?php
       $custom_fields = get_post_custom(3);
       foreach ( $custom_fields as $key => $values) {
          if ($key == 'key_5') continue;
          foreach ( $values as $value) {
             echo $key . " => " . $value . "<br />";
          }
       }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How to Get all Custom Fields Except One(or some)?’ is closed to new replies.