Viewing 4 reply threads
  • Author
    Posts
    • #7236
      beades48
      Participant

      I’m fairly new to Piklist and WordPress. I have an issue that is giving me a headache. I have a created a content type via Piklist for staff. Within this content type I have two fields that I would like to loop over when displaying the content. The first is the organizational level for the staff member (are they a department head, director, or plain staff). The second loop would sort each organizational level by last name.

      I am able to do this using array_multisort();. Is this the best method? Is there a better way in WordPress that I am missing? How can I get WordPress to see the custom fields I have created? I tried meta_key and key, neither worked. When I use WP_query, I get strange results.

      Any help is greatly appreciated. Sorry for the newbie question!

      Lynn

    • #7248
      Steve
      Keymaster

      @beades48– Welcome to the Piklist community!

      Please post your field code here so we can help you better.

    • #7253
      beades48
      Participant

      Hi Steve!

      The meta-boxes I am trying to perform the loop over:

      piklist(‘field’, array(
      ‘type’ => ‘text’,
      ‘field’ => ‘last_name’,
      ‘label’ => ‘Last Name’,
      ‘required’ => ‘required’,
      ‘attributes’ => array(
      ‘class’ => ‘regular-text’ // WordPress css class
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘select’,
      ‘field’ => ‘org_level’,
      ‘label’ => ‘Organizational Level’,
      ‘value’ => ‘0’,
      ‘choices’ => array(
      ‘0’ => ‘Staff’,
      ’20’ => ‘Department Head’,
      ’40’ => ‘Director’
      )
      ));

      I have tried the following in my function hsl_staff_list ()

      $args = array(
      ‘post_type’ => ‘hsl_staff’,
      ‘post_status’ => ‘publish’,
      ‘numberposts’ => -1,
      ‘meta_query’ => array(
      array (
      ‘key’ => ‘show_directory’,
      ‘value’ => ‘yes’,
      ‘organization’ => array(
      ‘key’ => ‘org_level’,
      ),
      ‘lastname’ => array(
      ‘key’ => ‘last_name’,
      ),
      ),
      ),
      ‘orderby’ => array (
      ‘organization’ => ‘DESC’,
      ‘lastname’ => ‘ASC’,
      ),
      );

      It did order by organization level, but not last name.

      $args = array(
      ‘post_type’ => ‘hsl_staff’,
      ‘post_status’ => ‘publish’,
      ‘numberposts’ => -1,
      ‘meta_query’ => array(
      array (
      ‘key’ => ‘show_directory’,
      ‘value’ => ‘yes’,
      ‘organization’ => array(
      ‘key’ => ‘org_level’,
      ‘value’ => ”,
      ),
      ‘lastname’ => array(
      ‘key’ => ‘last_name’,
      ‘value’ => ”,
      ),
      ),
      ),
      ‘orderby’ => array (
      ‘lastname’ => ‘ASC’,
      ‘organization’ => ‘DESC’,
      ),
      );

      I received the same result as above.

      $args = array(
      ‘post_type’ => ‘hsl_staff’,
      ‘post_status’ => ‘publish’,
      ‘numberposts’ => -1,
      ‘meta_query’ => array(
      array (
      ‘key’ => ‘show_directory’,
      ‘value’ => ‘yes’,
      ),
      ‘meta_key’ => array (‘org_level’, ‘last_name’),
      ‘orderby’ => array (‘meta_value’ => ‘DESC’, ‘meta_value’ => ‘ASC’),
      ),
      );

      This did not order by either organizational level or last name.

      I’m sure it is something that I am missing. I really appreciate the help!

      Lynn

    • #7275
      Steve
      Keymaster

      What data are you trying to get? All Names associated with a certain org_level?

    • #7278
      beades48
      Participant
      This reply has been marked as private.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.