admin管理员组

文章数量:1287833

So I'm building this post query array:

$posts = get_posts(array(
    'author'        =>  $publisher_info-ID,
    'post_type'         => 'post',
    'posts_per_page'    => 150,
    'meta_query' => array(
    array(
        'taxonomy' => 'type',
        'field'    => 'slug',
        'terms'    => array( 'campaign' ),
    ),
    array(
         'key'     => 'status',
         'value'   => 'active',
        ),
    ),
    
    'orderby'      => 'rand'
));

What I'm struggling is how to integrate two meta key comparison?

Let's say I have two meta keys meta_key A1 and meta_key A2.

Both have numbers in their meta_value.

What I want is to incorporate: A1 < A2 in the array.

Any help would be appreciated.

So I'm building this post query array:

$posts = get_posts(array(
    'author'        =>  $publisher_info-ID,
    'post_type'         => 'post',
    'posts_per_page'    => 150,
    'meta_query' => array(
    array(
        'taxonomy' => 'type',
        'field'    => 'slug',
        'terms'    => array( 'campaign' ),
    ),
    array(
         'key'     => 'status',
         'value'   => 'active',
        ),
    ),
    
    'orderby'      => 'rand'
));

What I'm struggling is how to integrate two meta key comparison?

Let's say I have two meta keys meta_key A1 and meta_key A2.

Both have numbers in their meta_value.

What I want is to incorporate: A1 < A2 in the array.

Any help would be appreciated.

Share Improve this question asked Sep 15, 2021 at 9:18 robert0robert0 2032 silver badges11 bronze badges 1
  • 1 Your meta_query contains a taxonomy query that should be in the tax_query arg, and you're also missing > here: $publisher_info-ID ... – Sally CJ Commented Sep 15, 2021 at 9:30
Add a comment  | 

1 Answer 1

Reset to default -1

Use this type of code :

$args = array(
    'author'        =>  $publisher_info->ID,
    'post_type' => 'post',
    'tax_query' => array(
            array(
                'taxonomy' => 'type',
                'field'    => 'slug',
                'terms'    => array( 'campaign' ),
            )
        ),
    'meta_query' => array(
            'relation' => 'AND',
            array(
                    'key' => 'status',
                    'value' => 'active',
                    'compare' => '='),
            array(
                    'key' => 'B',
                    'value' => '1',
                    'compare' => '!=')
            )
);
$data = new WP_Query($args);

本文标签: phpHow to set if metavalue is lower lt than other metavalue in a getposts array