Extend meta query arguments

I have this meta query:$args = array('post_type' => 'events','meta_query' => array(

I have this meta query:

$args = array(
    'post_type' => 'events',
    'meta_query' => array(
        array(
            'key' => 'fl_type',
            'value' => 'Awards'
        )
    ),
    'posts_per_page' => -1,
    'meta_key' => 'fl_order',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'fields' => 'ids'
);

However I need to extend this by another 2 numeric variables fl_expire = 0 and fl_global = 1 and I can't figure out the correct syntax for this.

I have this meta query:

$args = array(
    'post_type' => 'events',
    'meta_query' => array(
        array(
            'key' => 'fl_type',
            'value' => 'Awards'
        )
    ),
    'posts_per_page' => -1,
    'meta_key' => 'fl_order',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'fields' => 'ids'
);

However I need to extend this by another 2 numeric variables fl_expire = 0 and fl_global = 1 and I can't figure out the correct syntax for this.

Share Improve this question edited Jul 2, 2020 at 9:39 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Jul 1, 2020 at 20:50 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 2
  • Can you format your code with newlines and indentation? It's all written on a single line making it extremely difficult to read – Tom J Nowell Commented Jul 1, 2020 at 21:11
  • Ok I have done this now – JoaMika Commented Jul 2, 2020 at 9:28
Add a comment  | 

1 Answer 1

Reset to default 1

Try this

$args = array(
    'post_type' => 'events',
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'fl_type',
            'value' => 'Awards'
        ),
        array(
            'key' => 'fl_expire',
            'value' => 0,
            'type' => 'NUMERIC',
        ),
        array(
            'key' => 'fl_global',
            'value' => 1,
            'type' => 'NUMERIC',
        ),
    ),
    'posts_per_page' => -1,
    'meta_key' => 'fl_order',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'fields' => 'ids'
);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742298877a4417665.html

相关推荐

  • Extend meta query arguments

    I have this meta query:$args = array('post_type' => 'events','meta_query' => array(

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信