Support » Fixing WordPress » meta_query don't work on WP_Query – it's shows all posts

  • Hi,

    Im trying to get an result with an “new WP_Query” – it works, but not with the meta_query values. It’s results all posts.

    What i’m doing wrong!?

    Here s my code:

    $userid = $_GET['userid'];
    $visits1_id = $visits1['venid'];
    
    $visits_args = array(
              'post_type' => 'post' ,
              'post_status' => 'publish' ,
              'cat' => 129 ,
              'meta_query' => array(
                        array(
                                  'meta_key' => 'userid' ,
                                  'meta_value' => $visits1_id
                        ),
                        array(
                                  'meta_key' => 'placeid' ,
                                  'meta_value' => $placeid
                        ) )
              );
    
    $get_visits = new WP_Query( $visits_args );
    $visits1_count = $get_visits->post_count;
    
    if($visits1_count == 0){ $visit = ''; } else { $visit = 'ok'; }

    The last line gives an OK if there’s some posts where the placeid and userid is like the strings.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘meta_query don't work on WP_Query – it's shows all posts’ is closed to new replies.