Viewing 2 reply threads
  • Author
    Posts
    • #6234
      martinw
      Member

      I’m trying out Piklist and so far it’s really great!

      Currently i try to add relationships to custom-post-types as well as users.

      So i need to add a field to the user where administrators can select none or one entry from a custom-post-type.
      This is what i have/found and added to the parts/users-folder.
      So far it works, but i can not select an emtpy option, i always have to select an existing post.
      Is it possible to add an emtpy option to the top of the list?
      how would i do that?

      
      piklist('field', array(
          'type' => 'select'
          , 'field' => 'current_selection'
          , 'label' => __('Current Selection')
          , 'description' => __('Currently selected Post')
          , 'attributes' => array(
              'class' => 'text'
          )
          , 'choices' => piklist(            
              get_posts(array(
                  'post_type' => 'my-custom-post-type',
                  'numberposts' => -1,
                  'orderby' => 'title',
                  'order' => 'ASC'
              )), array('ID', 'post_title')
          ),
      ));
      
    • #6235
      martinw
      Member

      Did it!

      
      $array = array_merge(
          array(0 => "--- None ---"),
          piklist(            
              get_posts(array(
                  'post_type' => 'my-custom-post-type',
                  'numberposts' => -1,
                  'orderby' => 'title',
                  'order' => 'ASC'
              )), array('ID', 'post_title')
          )
      );
      piklist('field', array(
          'type' => 'select'
          , 'field' => 'current_selection'
          , 'label' => __('Current Selection')
          , 'description' => __('Currently selected Post')
          , 'attributes' => array(
              'class' => 'text'
          )
          , 'choices' => $array
      ));
      
    • #6238
      Steve
      Keymaster

      Nice! Closing ticket.

Viewing 2 reply threads
  • The topic ‘work with relationships’ is closed to new replies.