Tagged: , ,

Viewing 2 reply threads
  • Author
    Posts
    • #1243
      sanderschat
      Member

      Hi,
      i think i still dont fully get this, hence my question:

      i have a user custom field created:

      piklist('field', array('type'    => 'select',
                             'field'   => 'user_school',
                             'label'   => 'School',
                             'choices' => piklist(get_terms('school', array('hide_empty' => FALSE)), array("term_id",
                                                                                                           "name"))));

      But instead of the ‘term_id’ i need to have a custom field of this given taxonomy ‘school’.

      i think i need to use an sql-statement to get ‘name’ and the value of the custom field.
      But how to get this result into the ‘choices’ field?

      thanks!

    • #1244
      sanderschat
      Member

      A good night sleep will help…. 🙂
      I thought to give it a try myself and yes, figured out the answer:

      global $wpdb;
      piklist('field', array('type'    => 'select',
                             'field'   => 'user_school',
                             'label'   => 'School',
                             'choices' => piklist($wpdb->get_results("select
      t.name, tm.meta_value as 'legacy_id'
      from {$wpdb->prefix}term_taxonomy tt
      inner join {$wpdb->prefix}terms t
      on t.term_id = tt.term_id
      inner join {$wpdb->prefix}termmeta tm
      on tt.term_id = tm.term_id
      where
      tt.taxonomy='school'
      and
      tm.meta_key ='legacy_id'"), array("legacy_id",
                                        "name"))));

      thanks!

    • #1248
      Steve
      Keymaster

      @sanderschat– Great job. Remember, Piklist does things the normal WordPress/PHP way. So getting the choices list would be the same if you were even generating a standard HTML form.

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