Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am simply trying to print the value of a custom field. I have read all the documentation, tried out other people's suggestions, and nothing works. I can get it to print the ID #, but not the actual value I have in the field. I am using the Types plugin to create the field.

this prints the ID:

<?php echo get_the_ID($value, 'authorinfo', true); ?>

as well as:

<?php echo get_the_ID($key, 'authorinfo', true); ?>

this does nothing:

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

this does nothing:

<?php echo get_post_meta(get_the_ID(), 'authorinfo', true); ?>

(I have a separate question on this site where the problem came up and a solution was offered but unfortunately it didn't work for me) - Display custom post type and custom fields within a Bootstrap Carousel

Here is all the code I'm working within in case that helps. I hope I'm doing something stupid here.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div id="myCarousel" class="carousel">
        <div class="carousel-inner">

          <?php $the_query = new WP_Query(array(
            'post_type' => 'testimonial', 
            'posts_per_page' => 1 
            ));
            while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <div class="item active" data-title="">
                <div class="slide-copy">
                    <?php the_content();?>
                    <span class="byline"><?php echo get_post_meta(get_the_ID(), 'authorinfo', true); ?></span>
                </div>
            </div>
            <?php endwhile; wp_reset_postdata(); ?>
            <?php $the_query = new WP_Query(array(
            'post_type' => 'testimonial', 
            'posts_per_page' => 5, 
            'offset' => 1 
            ));
            while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <div class="item" data-title="">
                <div class="slide-copy">
                    <?php the_content();?>
                    <span class="byline"><?php echo get_post_meta(get_the_ID(), 'authorinfo', true); ?></span>
                </div>
            </div>

            <?php endwhile; wp_reset_postdata(); ?>
          </div>
        </div>
      </div><!-- end myCarousel -->

<?php endwhile; ?>      

EDIT/ADDITION

Since working with the Types plugin more, I am pretty sure this problem could be solved by using "types_render_field" instead of "get_post_meta". I don't have a place where I can test this, but I think this should help someone with a similar problem.

share|improve this question
    
<?php echo get_post_meta(get_the_ID(), 'authorinfo', true); ?> is correct. If it's not working, it might have something to do with how your plugin saves the data. Can't say further as i'm unfamiliar with that plugin –  Mridul Aggarwal Nov 12 '12 at 20:37
    
@Mridul Aggarwal thank you! –  cindyg Nov 12 '12 at 22:06
add comment

2 Answers

up vote 1 down vote accepted

The Types plugin is making this about 10x harder than it needs to be, you'll have to look through their documentation on the issue, but from what I can tell they don't store items in the postmeta table in a straightforward way. I created a simple field with the plugin in a sandbox env and the meta_key for a field I named data was wpcf-data. You may want to take your post ID and do this in your DB:

SELECT * FROM wp_postmeta WHERE post_id = NNNN;

where NNNN is your post ID. You may see a wpcf-authorinfo key, that is likely then the key you should be passing to get_post_meta:

echo get_post_meta(get_the_ID(), 'wpcf-authorinfo', TRUE);
share|improve this answer
    
thanks, you are awesome. unfortunately with my deadline today i am going to pass on trying that out, but i'm going to mark it as an answer because it sounds like it might help someone else. i decided to switch to the Advanced Custom Fields plugin and now i'm back in business. thanks! –  cindyg Nov 13 '12 at 15:43
    
Also possibly helpful for tracking down the actual meta_key you could use SELECT * FROM wp_postmeta WHERE meta_key LIKE '%authorinfo%'; –  totels Nov 13 '12 at 15:49
    
Way old post obviously, but I can confirm that Types adds wpcf- as a prefix to any custom meta fields you make with it. –  helgatheviking Jun 28 '13 at 1:05
add comment

I would try:

echo get_post_meta( $the_query->post->ID, 'authorinfo', true);

although I do agree with Mridul Aggarwal that

<?php echo get_post_meta(get_the_ID(), 'authorinfo', true); ?>

should also work.

share|improve this answer
    
Thank you! I'm going to mark this as the answer, even though it didn't fix it for me. I'm ruling my problem as a fluke. Gonna experiment with some other options for custom fields. (btw, diggin' your bootstrap theme!) –  cindyg Nov 12 '12 at 22:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.