Add custom order to staff jobs

This commit is contained in:
Brian Miyaji
2017-11-18 19:29:42 +11:00
parent 77f46b23b0
commit 5f150971f1
4 changed files with 42 additions and 9 deletions

View File

@@ -49,7 +49,7 @@ class SP_Staff extends SP_Custom_Post {
* @return array
*/
public function role() {
$roles = get_the_terms( $this->ID, 'sp_role' );
$roles = $this->get_roles();
if ( $roles && ! is_wp_error( $roles ) ):
return array_shift( $roles );
else:
@@ -64,11 +64,37 @@ class SP_Staff extends SP_Custom_Post {
* @return array
*/
public function roles() {
$roles = get_the_terms( $this->ID, 'sp_role' );
$roles = $this->get_roles();
if ( $roles && ! is_wp_error( $roles ) ):
return (array) $roles;
else:
return array();
endif;
}
public function get_roles() {
$roles = get_the_terms( $this->ID, 'sp_role' );
if ( ! is_array( $roles ) || ! sizeof( $roles ) ) return array();
$include = wp_list_pluck( $roles, 'term_id' );
return get_terms( array(
'taxonomy' => 'sp_role',
'hide_empty' => false,
'orderby' => 'meta_value_num',
'include' => $include,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS'
),
),
) );
}
}