Forums

[resolved] Getting values from custom fields (6 posts)

  1. boscardin
    Member
    Posted 3 months ago #

    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.

  2. Otto42
    Moderator
    Posted 3 months ago #

    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.

  3. boscardin
    Member
    Posted 3 months ago #

    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.

  4. Otto42
    Moderator
    Posted 3 months ago #

    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.

  5. buckyboog
    Member
    Posted 1 month ago #

    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

  6. buckyboog
    Member
    Posted 1 month ago #

    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', '', '','') .  '"> ';
            }
    ?>

Reply

You must log in to post.

About this Topic