Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Displaying all the output from your custom meta box
<?php get_header(); ?>
<?php
$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 ); ?>
<h1>Title</h1>
<?php the_title(); ?>
<h1>Content</h1>
<?php the_content(); ?>
<h1>Excerpt</h1>
<?php the_excerpt(); ?>
<h1>Text Input</h1>
<?php echo $meta['text']; ?>
<h1>Textarea</h1>
<?php echo $meta['textarea']; ?>
<h1>Checkbox</h1>
<?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>
<?php
switch ( $meta['select'] ) {
case 'option-one':
echo 'Option One';
break;
case 'option-two':
echo 'Option Two';
break;
default:
echo 'No option selected';
break;
}
?>
<h1>Image</h1>
<img src="<?php echo $meta['image']; ?>">
<?php endwhile; endif; wp_reset_postdata(); ?>
<?php get_footer(); ?>
@bharath007hyd

This comment has been minimized.

Copy link

bharath007hyd commented Apr 4, 2017

hi

@taniarascia

This comment has been minimized.

Copy link
Owner Author

taniarascia commented Aug 10, 2017

Uh hey.

@upeshv

This comment has been minimized.

Copy link

upeshv commented Sep 27, 2017

Hi,

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']; ?>" />
@dzynx

This comment has been minimized.

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

@AhsanAzeem

This comment has been minimized.

Copy link

AhsanAzeem commented May 10, 2019

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

@divyashu20

This comment has been minimized.

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
You can’t perform that action at this time.