• Resolved Kristy LaPorte

    (@kristy-laporte)


    I want to be able to display the meta data of the posts, but only the value, not the key. (For example, if the key was “Name of Person Quoted” and the value was “Brian”, I only want to display “Brian”.) Is this possible in vanilla WordPress 3.1, and if so, what code do I use? I’ve been Googling like mad but I’m just not getting it. (I’m a newb with PHP, in case you couldn’t tell. :P)

Viewing 12 replies - 1 through 12 (of 12 total)
  • <?php get_post_meta($post->ID, "key", true); ?>

    where key is your key, this will spit out the value. Used in the loop, in your template where you want it displayed

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    I tried this in my loop in the template, but nothing is showing. ??

    <p>
    <?php get_post_meta($post->ID, "For Featured Clients: Person Quoted", true); ?> <br />
    <?php get_post_meta($post->ID, "For Featured Clients: Position of Person Quoted", true); ?> <br />
    <?php get_post_meta($post->ID, "For Featured Clients: Company of Person Quoted", true); ?> <br />
    </p>

    I’ve also tried:

    <p>
    <?php echo get_post_meta($post->ID, "For Featured Clients: Person Quoted", true); ?> <br />
    <?php echo get_post_meta($post->ID, "For Featured Clients: Position of Person Quoted", true); ?> <br />
    <?php echo get_post_meta($post->ID, "For Featured Clients: Company of Person Quoted", true); ?> <br />
    </p>

    oh jeez, I forgot the echo, my apologies…

    get just ‘gets’ the info, it must be echoed out to be visible

    <?php echo get_post_meta($post->ID, "key", true); ?>

    oh, your second example has that

    I wonder if it’s your key names? I usually use all lowercase, no spaces

    like my_custom_field_key

    Maybe make a test key/value like that, or just using one word and see how that works

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    Ok, I will try changing the keys and see if that works. ??

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    Hmm, still nothing…

    Is there something I need to put in functions.php in order for this to work?

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    Oh, I should mention that I’m trying to do this on a page, although I do have the plugin Exec-PHP enabled so that I can use PHP in pages and posts.

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    And since the value is usually more than one word, such as “FirstName LastName”, does that mean that I want the data returned as an array rather than a string?

    Nah, multiple words in the value are fine

    You’re inputting that code directly into a post/page?

    I have no idea if that will work or not.

    Nothing needs to go into your functions.php for a simple get_post_meta to work.

    I use this all over the place and it works all the time. Only thing I can think of really is if you are inputting the code into a page, rather than directly into a template…..

    try to add <?php global $post; ?> before your code.

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    The rest of the loop works fine — I have it displaying the two most recent posts from a specific category, and that functions exactly as it should. Maybe Exec-PHP only allows SOME php to work, but not others? That confuses me since you’d expect that WordPress specific functions should work anywhere…

    I’ll do some plug-in searches and see if I get more info from that. Maybe I need another plugin to make it work.

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    Alchy: Immediately before the get-the-meta code?

    Thread Starter Kristy LaPorte

    (@kristy-laporte)

    Alchy: That seems to be what I’m missing!

    Thanks guys! You’ve both been super helpful. I seem to have it under control now. ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Possible to display only values of’ is closed to new replies.