Created
August 10, 2016 18:09
-
-
Save taniarascia/412a22c2ad0c500df8e7197571a50db4 to your computer and use it in GitHub Desktop.
Displaying all the output from your custom meta box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); ?> |
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
@upeshve i'm having that problem too. did you get a solution of this ?
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
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 ); ?>