admin管理员组文章数量:1391776
I have a custom post type Event that I use in conjunction with ACF. I have a group called event and inside that group I have a field called date_start. And this is the code that I currently have, but it filters instead of sorts, meaning every past event is not visible.
$args = array(
'post_type' => 'events',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'event_date_start' ,
'compare' => '>=',
'value' => current_time('Ymd'),
)
),
'meta_key' => 'event_date_start',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
Also, I have tried this code to no avail from a similar question here.
$args = array(
'post_type' => 'events',
'posts_per_page' => '-1',
'orderby' => 'meta_value_num ',
'meta_key' => 'event_date_start',
'order' => 'ASC'
);
Doing meta_value_num date
instead meta_value_num
didn't product desired result either. So, my question is, is there a way to sort these events and not filter theme, so every event would be visible and the most current would be displayed first.
Any help or ideas is much appreciated.
Update
adding 'type' => 'DATE',
to meta-query
didn't solve the problem.
Here is the var_dump($post);
object(WP_Post)[7713]
public 'ID' => int 974
public 'post_author' => string '1' (length=1)
public 'post_date' => string '2020-01-16 13:40:21' (length=19)
public 'post_date_gmt' => string '2020-01-16 13:40:21' (length=19)
public 'post_content' => string '' (length=0)
public 'post_title' => string '24 - 25 февраля' (length=22)
public 'post_excerpt' => string '' (length=0)
public 'post_status' => string 'publish' (length=7)
public 'comment_status' => string 'closed' (length=6)
public 'ping_status' => string 'closed' (length=6)
public 'post_password' => string '' (length=0)
public 'post_name' => string '24-25-fevralya' (length=14)
public 'to_ping' => string '' (length=0)
public 'pinged' => string '' (length=0)
public 'post_modified' => string '2020-01-16 13:40:21' (length=19)
public 'post_modified_gmt' => string '2020-01-16 13:40:21' (length=19)
public 'post_content_filtered' => string '' (length=0)
public 'post_parent' => int 0
public 'guid' => string '/?post_type=events&p=974' (length=48)
public 'menu_order' => int 5
public 'post_type' => string 'events' (length=6)
public 'post_mime_type' => string '' (length=0)
public 'comment_count' => string '0' (length=1)
public 'filter' => string 'raw' (length=3)
I have a custom post type Event that I use in conjunction with ACF. I have a group called event and inside that group I have a field called date_start. And this is the code that I currently have, but it filters instead of sorts, meaning every past event is not visible.
$args = array(
'post_type' => 'events',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'event_date_start' ,
'compare' => '>=',
'value' => current_time('Ymd'),
)
),
'meta_key' => 'event_date_start',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
Also, I have tried this code to no avail from a similar question here.
$args = array(
'post_type' => 'events',
'posts_per_page' => '-1',
'orderby' => 'meta_value_num ',
'meta_key' => 'event_date_start',
'order' => 'ASC'
);
Doing meta_value_num date
instead meta_value_num
didn't product desired result either. So, my question is, is there a way to sort these events and not filter theme, so every event would be visible and the most current would be displayed first.
Any help or ideas is much appreciated.
Update
adding 'type' => 'DATE',
to meta-query
didn't solve the problem.
Here is the var_dump($post);
object(WP_Post)[7713]
public 'ID' => int 974
public 'post_author' => string '1' (length=1)
public 'post_date' => string '2020-01-16 13:40:21' (length=19)
public 'post_date_gmt' => string '2020-01-16 13:40:21' (length=19)
public 'post_content' => string '' (length=0)
public 'post_title' => string '24 - 25 февраля' (length=22)
public 'post_excerpt' => string '' (length=0)
public 'post_status' => string 'publish' (length=7)
public 'comment_status' => string 'closed' (length=6)
public 'ping_status' => string 'closed' (length=6)
public 'post_password' => string '' (length=0)
public 'post_name' => string '24-25-fevralya' (length=14)
public 'to_ping' => string '' (length=0)
public 'pinged' => string '' (length=0)
public 'post_modified' => string '2020-01-16 13:40:21' (length=19)
public 'post_modified_gmt' => string '2020-01-16 13:40:21' (length=19)
public 'post_content_filtered' => string '' (length=0)
public 'post_parent' => int 0
public 'guid' => string 'http://emtway.local/?post_type=events&p=974' (length=48)
public 'menu_order' => int 5
public 'post_type' => string 'events' (length=6)
public 'post_mime_type' => string '' (length=0)
public 'comment_count' => string '0' (length=1)
public 'filter' => string 'raw' (length=3)
Share
Improve this question
edited Jun 15, 2020 at 8:21
CommunityBot
1
asked Feb 6, 2020 at 6:30
ivan marchenkoivan marchenko
1491 silver badge6 bronze badges
1 Answer
Reset to default 0In meta_query
, you missed the type of the field:
$args = array(
'post_type' => 'events',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'event_date_start' ,
'compare' => '>=',
'value' => current_time('Ymd'),
'type' => 'DATE',
)
),
'meta_key' => 'event_date_start',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
本文标签: Sort custom post type by custom datepicker instead of filtering
版权声明:本文标题:Sort custom post type by custom datepicker instead of filtering 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744771221a2624350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论