[英]Wordpress how to sort posts according to Custom Field
I tried all solutions given on this site or other websites but did not find success in sorting posts according to custom field payment package.我尝试了本网站或其他网站上给出的所有解决方案,但没有发现根据自定义字段付款包对帖子进行排序的成功。 I tried below code
我试过下面的代码
$args = array( 'meta_key'=>'et_payment_package','meta_key'=>693 );
// Variable to call WP_Query.
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
// Start the Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
the_excerpt();
// End the Loop
endwhile;
else:
// If no posts match this query, output this text.
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
wp_reset_postdata();
It shows表明
Sorry, no posts matched your criteria.
对不起,没有职位符合您的标准。
Your query arguments are wrong.您的查询参数是错误的。 You have
meta_key
twice.你有两次
meta_key
。 Try with试试
$args = array( 'meta_key'=>'et_payment_package', 'meta_value'=>693 );
And try to specify the post type.并尝试指定帖子类型。
For instance:例如:
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'et_payment_package',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'et_payment_package',
'value' => '693',
'compare' => 'IN',
),
),
);
$query = new WP_Query( $args );
I don't have all the details (post type etc), but this is how you'd go about it.我没有所有的细节(帖子类型等),但这就是你要做的。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.