Tagged: conditional fields, get_posts, select, settings
- This topic has 6 replies, 3 voices, and was last updated 6 years, 3 months ago by
Steve.
-
AuthorPosts
-
-
October 15, 2015 at 11:17 am #4594
RachelMemberI’m trying to create a conditional field for a settings page that will display a preview of the post chosen, but couldn’t find a way to add a condition for something != none.
Here’s what I have:
piklist('field', array( 'type' => 'select' ,'field' => 'featured_post_id' ,'label' => 'Choose post to feature' ,'columns' => 6 ,'choices' => array('none' => '-') + piklist( get_posts( array( 'post_type' => 'post' ,'orderby' => 'post_date' ) ,'objects' ) ,array( 'ID' ,'post_title' ) ) )); piklist('field', array( 'type' => 'html' ,'label' => 'Post Selected' ,'field' => 'featured_post_preview' ,'description' => 'The selected post to be featured' ,'value' => '<img src="Post image"/><h2>Post Title</h2><p>Excerpt</p>' // How do I access these fields from the get_posts for the chosen featured_post_id? ,'conditions' => array( array( 'field' => 'featured_post_id' ,'value' => !'none' // how do I conditionally display based on when the value is not equal to none? ) ) ));Thank you for any help you can provide!
-
October 15, 2015 at 4:28 pm #4600
KevinKeymaster@Rachel-
Check out the compare option for conditions, I think that’s what your looking for.
https://piklist.com/user-guide/docs/field-parameters/conditions/
Thanks,
Kevin
-
October 22, 2015 at 4:06 pm #4704
RachelMemberGreat! That worked, now I just need to replace the image, title, and excerpt with the real thing.
piklist('field', array( 'type' => 'select' ,'field' => 'featured_post_id' ,'label' => 'Choose post to feature' ,'columns' => 6 ,'choices' => array('none' => '-') + piklist( get_posts( array( 'post_type' => 'post' ,'orderby' => 'post_date' ) ,'objects' ) ,array( 'ID' ,'post_title' ) ) )); piklist('field', array( 'type' => 'html' ,'label' => 'Post Selected' ,'field' => 'featured_post_preview' ,'description' => 'The selected post to be featured' ,'value' => '<img src="Post image"/><h2>Post Title</h2><p>Excerpt</p>' ,'conditions' => array( array( 'field' => 'featured_post_id' ,'value' => 'none' ,'compare' => '!=' ) ) )); -
October 26, 2015 at 10:49 am #4745
RachelMemberHow would I go about replacing them with the selected post title, image, and excerpt?
-
October 27, 2015 at 10:19 am #4760
SteveKeymaster@rcantor– I’m not sure I’m 100% clear on your request, so I hope this makes sense.
After the user selects
featured_post_id, they would need to save the page. Then you can use get_posts() to pull in the data you need. -
October 30, 2015 at 10:33 pm #4799
SteveKeymaster@rachel– Closing this ticket since we resolved via email.
-
-
AuthorPosts
- The topic ‘Creating conditional field for something not equal to 'none'’ is closed to new replies.