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(); ?> |
This comment has been minimized.
This comment has been minimized.
Uh hey. |
This comment has been minimized.
This comment has been minimized.
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 ); ?>
|
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
AhsanAzeem
commented
May 10, 2019
@upeshve i'm having that problem too. did you get a solution of this ? |
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
bharath007hyd commentedApr 4, 2017
hi