Viewing 5 reply threads
  • Author
    Posts
    • #4594
      Rachel
      Member

      I’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!

    • #4600
      Kevin
      Keymaster

      @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

    • #4704
      Rachel
      Member

      Great! 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' => '!='
             )
           )
         ));
    • #4745
      Rachel
      Member

      How would I go about replacing them with the selected post title, image, and excerpt?

    • #4760
      Steve
      Keymaster

      @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.

      • #4761
        Rachel
        Member

        That makes sense. I was trying to see if part of the condition could get the post info once the select option changes.

    • #4799
      Steve
      Keymaster

      @rachel– Closing this ticket since we resolved via email.

Viewing 5 reply threads
  • The topic ‘Creating conditional field for something not equal to 'none'’ is closed to new replies.