admin管理员组文章数量:1420086
I have a query using 'compare' -- trying to select where meta values are between certain dates:
$argsTwo = array(
'post_type' => 'event',
'meta_key' => '_event_information_year_select',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'relation' => 'AND',
array(
'key' => '_event_information_year_select',
'value' => 1999,
'compare' => '>'
),
array(
'key' => '_event_information_year_select',
'value' => 2003,
'compare' => '<='
)
)
)
);
My issue is this query only gives me results until 2002. I can't seem to figure out what is going wrong. The values definitely exist in the DB but these $args don't seem to work.
Any ideas?
Thanks
I have a query using 'compare' -- trying to select where meta values are between certain dates:
$argsTwo = array(
'post_type' => 'event',
'meta_key' => '_event_information_year_select',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'relation' => 'AND',
array(
'key' => '_event_information_year_select',
'value' => 1999,
'compare' => '>'
),
array(
'key' => '_event_information_year_select',
'value' => 2003,
'compare' => '<='
)
)
)
);
My issue is this query only gives me results until 2002. I can't seem to figure out what is going wrong. The values definitely exist in the DB but these $args don't seem to work.
Any ideas?
Thanks
Share Improve this question asked Jul 14, 2019 at 18:15 Best Dev TutorialsBest Dev Tutorials 4451 gold badge7 silver badges21 bronze badges 2 |1 Answer
Reset to default 1It looks like your meta_query is nested within an extra array. Aside from that, the code looks valid.
Hope this helps:
$argsTwo = array(
'post_type' => 'event',
'meta_key' => '_event_information_year_select',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_event_information_year_select',
'value' => 1999,
'compare' => '>'
),
array(
'key' => '_event_information_year_select',
'value' => 2003,
'compare' => '<='
)
)
);
本文标签: WP Query Compare cutting off last 2 dates
版权声明:本文标题:WP Query Compare cutting off last 2 dates 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745323563a2653488.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
event_information_year
taxonomy with terms for each year, then you could make atax_query
that's potentially 100x faster, easier to write, and provides a super easy to way to list the years in a UI on the frontend, as well as providing you with dedicated archive templates, and REST API endpoints? – Tom J Nowell ♦ Commented Jul 14, 2019 at 18:56