最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - meta_query BETWEEN, but the range is stored in the custom field

programmeradmin4浏览0评论

I've seen plenty of samples of using meta_query to find if the value is between a range, where the range looks something like this:

  $meta_query_args = [
    'key' => "custom_field",
    'value' => [ $_GET['start'], $_GET['end'] ],
    'compare' => 'BETWEEN',
    'type' => 'numeric',
  ];

I need to do kinda the opposite. My custom_field has the range, and I can $_GET the value I need to find if it's between that range or not. So if the value of custom_field is 4-8, and the value of $_GET['number'] is 5, it should match. Basically, I need something like this:

 $meta_query_args = [
    'key' => "custom_field", // This may be a range like 4-8, or a number like 7
    'value' => $_GET['number'], // This will be a single number, like 5
    'compare' => 'BETWEEN', // I need to figure if 5 is within the range 4-8
    'type' => 'numeric', // I will only deal with numbers.
  ];

However, as much as I've tried to find how to do this, I have failed. Any help would be appreciated.

发布评论

评论列表(0)

  1. 暂无评论