Support

Account

Home Forums General Issues Sorting posts by custom field's custom order Reply To: Sorting posts by custom field's custom order

  • Like this:

    $roles = array('Director', 'Lead Teacher', 'Teacher', 'Assistant Teacher');
    Also, roles could be populated from a taxonomy or from a custom post type.

    Then:

    
    $location = ''; // to be defined
    $facultys = array();
    
    foreach($roles as $role) {
    	$posts = get_posts(array(
    		'post_type’ => 'faculty’,
    		'order’ => 'ASC’,
    		'meta_query’ => array(
    			array(
    				'key’ => 'location’,
    				'value’ => $location,
    				'compare’ => 'LIKE’,
    			),
    			array(
    				'key’=> 'role’,
    				'value’ => $role,
    				'compare’ => 'LIKE’,
    			)
    		)
    	));
    
    	// Merge the posts result with the existing facultys
    	$facultys = array_merge($facultys, $posts);
    }