Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Displaying all the output from your custom meta box
<?php get_header(); ?>
$args = array(
'post_type' => 'your_post',
$your_loop = new WP_Query( $args ); if ( $your_loop->have_posts() ) : while ( $your_loop->have_posts() ) : $your_loop->the_post();
$meta = get_post_meta( $post->ID, 'your_fields', true ); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php the_excerpt(); ?>
<h1>Text Input</h1>
<?php echo $meta['text']; ?>
<?php echo $meta['textarea']; ?>
<?php if ( $meta['checkbox'] === 'checkbox') { ?>
Checkbox is checked.
<?php } else { ?>
Checkbox is not checked.
<?php } ?>
<h1>Select Menu</h1>
<p>The actual value selected.</p>
<?php echo $meta['select']; ?>
<p>Switch statement for options.</p>
switch ( $meta['select'] ) {
case 'option-one':
echo 'Option One';
case 'option-two':
echo 'Option Two';
echo 'No option selected';
<img src="<?php echo $meta['image']; ?>">
<?php endwhile; endif; wp_reset_postdata(); ?>
<?php get_footer(); ?>
Copy link

bharath007hyd commented Apr 4, 2017


Copy link

taniarascia commented Aug 10, 2017

Uh hey.

Copy link

upeshv commented Sep 27, 2017


I am having trouble in fetching the field value inside my functions on functions.php..

can you please help me with this below is my code which i am trying to add on functions.php and output seems to be blank nothing fetched.

'post', ); $your_loop = new WP_Query( $args ); if ( $your_loop->have_posts() ) : while ( $your_loop->have_posts() ) : $your_loop->the_post(); $meta = get_post_meta( $post->ID, 'additional_fields', true ); ?>
<meta content="<?php echo $meta['audio']; ?>" />

Copy link

dzynx commented Mar 8, 2019

I had multiple posts rendered on a page. I removed lines 5-8 and used the bare bone loop "if(have_posts()) : while ...etc. And it works - rendering one page per page

Copy link

AhsanAzeem commented May 10, 2019

@upeshve i'm having that problem too. did you get a solution of this ?

Copy link

divyashu20 commented Jun 14, 2019

Hey i want to display the value of meta box on page help me go on my profile and check my code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment