Display Meta Box Value on Page Template (1 post)

  1. hhamernik
    Posted 1 year ago #

    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(
    			'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>
     <!-- post--></div>
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
    <?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic