你好,我有一个自定义的帖子类型event
我有两个自定义字段:
我想显示所有具有event_type
= Featured
排序应按event_date
在里面DESC
顺序
我在SOF上到处搜索,但找不到任何有效的解决方案。。这是我的密码
$events = new WP_Query(
array(
\'post_type\' => \'event\',
\'post_status\' => \'publish\',
\'meta_key\' => \'event_type\',
\'meta_value\' => \'featured\',
\'posts_per_page\' => -1,
\'orderby\' => \'event_date\',
\'order\' => \'DESC\'
)
);
屏幕截图
最合适的回答,由SO网友:Faysal Mahamud 整理而成
请像这样更改您的参数。
$meta_query = array(
array(
\'key\' => \'event_type\',
\'value\' => \'featured\',
\'compare\' => \'=\'
)
);
$args = array(
\'post_type\' => \'event\',
\'posts_per_page\' => -1,
\'order\' => \'DESC\',
\'orderby\' => \'meta_value_num\',
\'meta_key\' => \'event_date\',
\'meta_query\' => $meta_query
);