Tagged: loop, multidimensional
- This topic has 4 replies, 2 voices, and was last updated 5 years, 5 months ago by
beades48.
-
AuthorPosts
-
-
August 24, 2016 at 2:20 pm #7236
beades48ParticipantI’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
-
August 25, 2016 at 11:16 pm #7248
-
August 26, 2016 at 7:59 am #7253
beades48ParticipantHi 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
-
August 29, 2016 at 8:38 pm #7275
SteveKeymasterWhat data are you trying to get? All Names associated with a certain org_level?
-
August 30, 2016 at 7:54 am #7278
beades48ParticipantThis reply has been marked as private.
-
-
AuthorPosts
- You must be logged in to reply to this topic.