I am working on a project where I have to show a list of woo-commerce orders where a particular postcode/zip code exists. I am using hook pre_get_posts to achieve that when I pass a single key and value order start showing but when I add multiple key and values no order is showing. The code I am using is from wordpress.stackexchange.com but still, it is not working for multiple keys and values.

I am sure there is something wrong in the code that I can identify any help will be appreciated. Thanks

add_action( 'pre_get_posts', array($this, 'zipcode_wise_post_filter') );
function zipcode_wise_post_filter( $query ) {

if( !$query->is_main_query() ) return;

if(isset(wp_get_current_user()->roles[0]) && wp_get_current_user()->roles[0] == 'order_manager'){
    $user_id = get_current_user_id();
    $zip_code = array(60643,1600, 02134);

    $meta_query = $query->get("meta_query");
    $meta_query = array(
        "relation" => "AND",

    $query->set('post_type', 'shop_order' );

    foreach ($zip_code as $code) {
      $meta_query[]  =   array(
          'compare' => 'EXISTS',

    $query->set('meta_query',$meta_query ); 


return $query; 

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.