• Resolved boscardin

    (@boscardin)


    I’m trying to make a movie review page and next to the title, I want to show just the value of my custom field. This is what I’ve put into WP:

    Key: Rating
    Value: (some image)

    Now, I’ve been reading this page to figure out how to do it, but no luck. I’ve tried to put in these two codes, but I get nothing in return:

    <?php echo get_post_custom_values('rating'); ?>
    
    <?php echo get_post_meta($post->ID, 'rating', true); ?>

    But again, neither one works. I can put in

    <?php the_meta(); ?>

    and it will print out the fields as a list, but I don’t want that.

    I’ve been testing by putting in the code in just one post to see if it will work (since technically, it’s still in The Loop). What you see at the bottom is the result of the the_meta call I put in.

    I’ve tried to do a search already in the WP forums, but no luck within the first few pages of my search. Any help with this is highly appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Key: Rating
    Value: (some image)

    <?php echo get_post_custom_values(‘rating’); ?>
    <?php echo get_post_meta($post->ID, ‘rating’, true); ?>

    Did you not notice that “Rating” is not the same thing as “rating”?

    Capitalization matters.

    Thread Starter boscardin

    (@boscardin)

    No, I did not know that capitalization mattered. Thanks for pointing that out for me. =)

    I used

    <?php echo get_post_meta($post->ID, 'rating', true); ?>

    And that spit out my image. The first one

    <?php echo get_post_custom_values('rating'); ?>

    gave me an array.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    That’s because it’s “values”. Plural. You’ll always get an array back from the get_post_custom_values call. The contents of that array will be the values.

    I am having a devil of a time getting an array of data out of a field with multiple values (checkbox list)

    I either get just one of the values or I get the word “Array”

    <?php echo get_post_custom_values(‘Modality’); ?>

    Gives “Array”

    or

    <?php if(get_post_custom_values(‘Modality’)) :
    foreach(get_post_custom_values(‘Modality’) as
    $modality) {} ?>
    <div class=”source”>Modality: <?php echo
    $modality; ?></div>
    <?php endif; ?>

    Only gives one of the values

    This is what ended up working:

    <?php $magazine_url= c2c_get_custom('Magazine URL');
           $magcheck=$magazine_url[0];
           if (!empty($magcheck)) {
               echo '<a href="' . c2c_get_custom('Magazine URL', '', '','') .  '"> ';
            }
    ?>

    I found a much easier solution, using the php implode() function to get the strings out of my array:

    <?php
    $cust_fld = get_post_meta($post->ID, "custom_field", false);
    if ($cust_fld[0]=="") {}
    else{
    echo implode("",$cust_fld);}
    ?>
    <!-- checks to see if there's anything in custom field "custom_field." If not, do nothing. If so, insert custom field entry with line breaks between each. -->

    Hope that helps someone!

    mofuzz, thanks a lot!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Getting values from custom fields’ is closed to new replies.