Display Meta Box Value on Page Template
-
I added a metabox to a custom post type. It displays and saves fine on the dashboard. I am using the following code which displays the value fine on single.php
echo get_post_meta( $post->ID, '$prefix . 'linkurl', true );
This does NOT display/ work on a page template though. I can’t find documentation on how to display meta box values on custom page templates. Here is the loop I am using just in case.
<?php $args = array( 'post_type'=>'sponsors', 'category_name' => 'sponsor-logos', 'posts_per_page' => 1 ); $wp_query = new WP_Query( $args );?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <div class="thumbnail"> <a target="_blank" href="<?php echo get_post_meta($post->ID, $prefix . 'linkurl', true); ?>"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thumbnail' ); } ?></a> <!--thumbnail--></div> <!-- post--></div> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>
- The topic ‘Display Meta Box Value on Page Template’ is closed to new replies.