You’ll need to use meta_query
along with meta_(key|value|compare)
to interact with two different keys and get the order you want.
<?php
$q = new WP_Query(array(
'post_type' => 'my_project',
'nopaging' => true, // same as posts_per_page => 1,
'order' => $order,
'orderby' => 'is_featured_position', // your position key here
'meta_key' => 'is_featured_position', // also here, see below
'meta_value_num' => 0, // you may want something different here
'meta_compare' => '>', // you may want something different here
'meta_query' => array(
array(
'key' => 'is_featured',
'copmare' => 'EXISTS', // only works in WP 3.5+
),
),
));
Okay, so when you use a combination of meta_(key|value|compare)
keys along with meta_query
some weirdness happens. WordPress uses the class WP_Meta_Query
to parse and create metadata queries. We can take a look inside WP_Meta_Query::parse_query_vars
to learn more.
/**
* Constructs a meta query based on 'meta_*' query vars
*
* @since 3.2.0
* @access public
*
* @param array $qv The query variables
*/
function parse_query_vars( $qv ) {
$meta_query = array();
// Simple query needs to be first for orderby=meta_value to work correctly
foreach ( array( 'key', 'compare', 'type' ) as $key ) {
if ( !empty( $qv[ "meta_$key" ] ) )
$meta_query[0][ $key ] = $qv[ "meta_$key" ];
}
// WP_Query sets 'meta_value' = '' by default
if ( isset( $qv[ 'meta_value' ] ) && '' !== $qv[ 'meta_value' ] )
$meta_query[0]['value'] = $qv[ 'meta_value' ];
if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
$meta_query = array_merge( $meta_query, $qv['meta_query'] );
}
$this->__construct( $meta_query );
}
The overall picture: meta_(key|value|compare)
keys just become part of the meta_query
array.
Unfortunately, WordPress only checks meta_key
for a valid orderby, so you must include it as well as a meta_query
with the remaining custom fields you want to use. In your case you must use the featured order field so you can use it the orderby
argument.
The above is untested, but it should at least get you started!