Viewing 4 reply threads
  • Author
    Posts
    • #11073
      guit4eva
      Participant

      Greetings!

      How would I show the following ONLY if the post id is 20,32 or 49?

      piklist('field', array(
          'type' => 'textarea',
          'field' => 'welcome-intro',
          'label' => 'Welcome',
         'type' => 'editor',
         'scope' => 'post_meta',
      ));
    • #11074
      Steve
      Keymaster

      You can do this for the entire meta box. Use the ID comment block parameter:
      https://docs.piklist.com/comment-block-parameters/#id

      id: 20, 32, 49

    • #11075
      guit4eva
      Participant

      Is it possible to do this though per single field? I need this to apply to one field, and not the whole metabox

    • #11076
      Steve
      Keymaster

      You can wrap the field in a PHP conditional statement. In future versions of Piklist this might not work as expected. It would better to place this field in it’s own meta box.

      Here’s an example of conditional code:

      
      global $post;
      
      $pages = array( 20, 32, 49 );
      
      if ( in_array( $post->ID, $pages ) ) {
      
      	piklist('field', array(
      		'type' => 'textarea',
      		'field' => 'welcome-intro',
      		'label' => 'Welcome',
      		'type' => 'editor',
      		'scope' => 'post_meta',
      	));
      
      }
    • #11118
      guit4eva
      Participant

      Ok, that makes sense. Thanks so much 🙂

Viewing 4 reply threads
  • The topic ‘Show field based on post ID’ is closed to new replies.