Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Created August 10, 2016 18:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taniarascia/412a22c2ad0c500df8e7197571a50db4 to your computer and use it in GitHub Desktop.
Save taniarascia/412a22c2ad0c500df8e7197571a50db4 to your computer and use it in GitHub Desktop.
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(); ?>
@AhsanAzeem
Copy link

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

@divyashu20
Copy link

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