admin管理员组

文章数量:1394093

I had a question that dont know why happen you use that query

  $parent_args = array(
        'post_type' => $parent_post_type_slug,
         'meta_key' => $child_post_field_key,
        'meta_value' => $user_field_value
    );

    $parent_posts = get_posts( $parent_args );

and work fine but if try to do this , the query return values that dont are correct

  $parent_args = array(
        'post_type' => $parent_post_type_slug,
          'meta_query' => array(
        array(
            'key'     => $child_post_field_key,
            'value'   => $user_field_value,
        ),
    );

    $parent_posts = get_posts( $parent_args );

I get a post that does not meet the condition

what am I doing wrong?

I had a question that dont know why happen you use that query

  $parent_args = array(
        'post_type' => $parent_post_type_slug,
         'meta_key' => $child_post_field_key,
        'meta_value' => $user_field_value
    );

    $parent_posts = get_posts( $parent_args );

and work fine but if try to do this , the query return values that dont are correct

  $parent_args = array(
        'post_type' => $parent_post_type_slug,
          'meta_query' => array(
        array(
            'key'     => $child_post_field_key,
            'value'   => $user_field_value,
        ),
    );

    $parent_posts = get_posts( $parent_args );

I get a post that does not meet the condition

what am I doing wrong?

Share Improve this question edited Mar 22, 2020 at 21:57 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Mar 21, 2020 at 17:34 Arucard7sArucard7s 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The Answer is: Nothing. These two snippets SHOULD return the same posts.

However, there are a lot of things, that can change a query before it is executed: plugins, your own theme by a pre_get_posts Filter. So to check if it is an error in this code or some other code, you can disable all plugins, switch to a standard theme, and THEN test your snippet again.

本文标签: Question about of query