Tagged: display, Front End, get_post_meta, single.php, theme
- This topic has 6 replies, 3 voices, and was last updated 6 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
March 22, 2014 at 5:19 am #1593
nadiaMemberHi there,
I’m really stuck. I just can’t seem to get my Piklist editor values to show in replace of the default WordPress values. Have looked through the forums which point me to the get_post_meta in WordPress help, but it’s just not helping.
I have created my demo_metabox.php file.
And within it have created a text field:
piklist(‘field’, array(
‘type’ => ‘text’
,’field’ => ‘subtitle’
,’label’ => ‘Subtitle Text Box’
,’description’ => ‘Enter the year of birth here’
,’value’ => ‘Default text’
,’help’ => ‘Example: b.1940′
,’attributes’ => array(
‘class’ => ‘text’
)
));
This is working, it now shows in the editor.
Great. Happy with this.In single.php I have called my custom fields in the same way I would normally.
<?php
$subtitle= get_post_meta($post->ID, ‘demo_subtitle’, true);
?><?php if($subtitle){?>
<h3><?php echo $subtitle;?></h3>
<?php } ?>This returns nothing.
I just can’t move forward until I figure out how to get the values coming through.Please help!
Cheers. -
March 22, 2014 at 12:21 pm #1594
SteveKeymasterYour field is
subtitlebut you’re pullingdemo_subtitle. They need to match. -
November 28, 2015 at 6:46 pm #5145
AnthonyMemberI think this thread is addressing a similar (basic problem) for me. I have a custom post type that I am using Piklist to relate to my regular posts. If the regular post has the related post checked off then it should display the singular template in a certain way otherwise it reverts to its default.
<?php while (have_posts()) : the_post(); ?> <?php $purchase = get_post_meta(get_the_ID(), 'sponsor', true ); var_dump( $purchase ); ?> <?php if( ! $purchase ) { ?> <div class="inner"> <ul class="author-post actions"> <li><a class="icon-wrapper circle" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"> <?php echo get_avatar( get_the_author_meta( 'ID' ), 48 ); ?> </a></li> <li><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"> <?php echo get_the_author();?></a> <br /><?php posted_on(); ?></li> <li><li><a href="<?php the_permalink();?>" class="button">Purchase</a></li></li> </ul> </div><!-- inner //-->The issue is that the var_dump reveals:
string(0) ""It’s simply not getting any results, therefore my template is always displaying the “false” conditional.
-
November 28, 2015 at 10:55 pm #5149
SteveKeymasterCan you post the field code for ‘sponsor’?
-
November 28, 2015 at 11:34 pm #5151
AnthonyMemberI RTFM the related posts section of the documentation and found that it was better to use get_posts() instead of get_post_meta():
?php if (have_posts()) : ?> <section id="main" class="wrapper style3"> <?php while (have_posts()) : the_post(); ?> <?php $purchasers = get_posts(array( 'post_type' => 'sponsor' ,'posts_per_page' => -1 ,'post_belongs' => $post->ID ,'post_status' => 'publish' ,'suppress_filters' => false // This must be set to false )); var_dump($purchasers); // do we have a pulse?I keep getting no results. Sorry about posting in the other thread. I thought it was cross related. No issue-pun intended.
-
November 29, 2015 at 11:04 am #5154
AnthonyMemberNever mind I figured it out. The code was correct.
-
November 30, 2015 at 4:26 pm #5162
SteveKeymasterGreat. Closing ticket.
-
-
AuthorPosts
- The topic ‘Basic front end help’ is closed to new replies.