您需要使用meta_query
随着meta_(key|value|compare)
使用两个不同的键进行交互并获得所需的顺序。
<?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+
),
),
));
好的,那么当你使用
meta_(key|value|compare)
钥匙以及
meta_query
有些奇怪的事情发生了。WordPress使用该类
WP_Meta_Query
分析和创建元数据查询。我们可以进去看看
WP_Meta_Query::parse_query_vars
了解更多信息。
/**
* 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 );
}
总体情况:
meta_(key|value|compare)
钥匙只是
meta_query
大堆
不幸的是,WordPress只检查meta_key
对于有效的orderby,您必须将其以及meta_query
与要使用的其余自定义字段一起使用。在您的情况下,您必须使用“特色订单”字段,以便在orderby
论点
以上内容未经测试,但至少应该让您开始!