admin管理员组文章数量:1386701
guys, I have a custom post type called "game" and it has some custom fields (get_post_meta) which I access by their keys "_game_date_key", "_game_home_goals_key" and "_game_away_goals_key".
How do I use the WP_Query() to return posts sorted by the "_game_date_key" and ("_game_home_goals_key" and "_game_away_goals_key") are numbers ?
guys, I have a custom post type called "game" and it has some custom fields (get_post_meta) which I access by their keys "_game_date_key", "_game_home_goals_key" and "_game_away_goals_key".
How do I use the WP_Query() to return posts sorted by the "_game_date_key" and ("_game_home_goals_key" and "_game_away_goals_key") are numbers ?
Share Improve this question asked May 8, 2020 at 9:14 Isakiye AfashaIsakiye Afasha 1371 silver badge8 bronze badges1 Answer
Reset to default 0You should add arguments to WP_Query to sort by your keys in the order you want. The compare value can be your filter (larger, smaller, etc)
$args = [
'meta_query' => array(
'relation' => 'AND',
'event_start_date_clause' => array(
'key' => '_game_date_key',
'compare' => 'EXISTS',
),
'event_start_time_clause' => array(
'key' => '_game_home_goals_key',
'compare' => 'EXISTS',
),
'event_start_time_clause' => array(
'key' => '_game_away_goals_key',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'_game_date_key' => 'ASC',
'_game_home_goals_key' => 'ASC',
'_game_away_goals_key' => 'ASC',
),
];
本文标签: How can I query and sort custompost type using WPQuery
版权声明:本文标题:How can I query and sort custom-post type using WP_Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744493780a2608894.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论