Viewing 4 reply threads
  • Author
    Posts
    • #375
      Sander Schat
      Member

      hi!
      is there way to add an extra choice to the ‘select’ dropdown when using it with a WP function, like so:

      piklist('field', array(
      'type' => 'select'
      ,'field' => 'search'
      ,'label' => 'seach page'
      ,'attributes' => array(
      'class' => 'text'
      )
      ,'choices' => piklist(
      get_pages(
      array(
      'sort_order' => 'ASC',
      'sort_column' => 'post_title',
      'post_type' => 'page',
      'post_status' => 'publish'
      )
      ,'objects'
      )
      ,array(
      'id'
      ,'post_title'
      )
      )
      ));

      this gets the pages, but i would like to add the ‘first’ option myself, to include it with a different text like ‘please select page…’

      Also, what does ‘objects’ mean in this case?

    • #376

      Hi,

      Here is what I did in my own code:

      [...]
      ,'choices' =>
      array('first-option-value' => 'first option label')
      +
      piklist( get_pages( [...] ) )
      [...]

      Hope it helps !

      Cheers,

      Daniel

    • #378
      Sander Schat
      Member

      yes, works!
      thanks

    • #382
      Kevin
      Keymaster

      Hi Guys-

      I do the same thing, however one thing to keep in mind is that the above method won’t work on all server setups. I usually try and stick with array_splice and array_push for these types of things just to be on the safe side 🙂

      Thanks,

      Kevin

    • #1634
      Sander Schat
      Member

      is it an ‘idea’ to have this as an extra option by default in Piklist?

      I do this with every field just to make it clear to the user,
      there is NO value selected when showing for the first time.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.