Guest User

Meta Query

a guest
Feb 19th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1.     $stylist_id = filter_input ( INPUT_POST, 'stylist_id', FILTER_SANITIZE_STRING);
  2.     $face_id = filter_input ( INPUT_POST, 'face_id', FILTER_SANITIZE_STRING);
  3.     $gender_id = filter_input ( INPUT_POST, 'gender_id', FILTER_SANITIZE_NUMBER_INT);
  4.     $skin_id = filter_input ( INPUT_POST, 'skin_id', FILTER_SANITIZE_STRING);
  5.     $hair_id = filter_input ( INPUT_POST, 'hair_id', FILTER_SANITIZE_STRING);
  6.    
  7.     $args = array(
  8.         'post_type' => 'product',
  9.         'meta_query' => array(
  10.             'relation' => 'AND',
  11.             array(
  12.                 'meta_key' => 'stylist',
  13.                 'meta_value' => $stylist_id,
  14.                 'compare' => '=',
  15.             ),
  16.             array(
  17.                 'meta_key' => 'face_shape',
  18.                 'meta_value' => $face_id,
  19.                 'compare' => '=',
  20.             ),
  21.             array(
  22.                 'meta_key' => 'skin_tone',
  23.                 'meta_value' => $skin_id,
  24.                 'compare' => '=',
  25.             ),
  26.             array(
  27.                 'meta_key' => 'hair_colour',
  28.                 'meta_value' => $hair_id,
  29.                 'compare' => '=',
  30.             ),
  31.         ),
  32.         'tax_query' => array(
  33.             array(
  34.                 'taxonomy' => 'product_cat',
  35.                 'field' => 'id',
  36.                 'terms' => $gender_id,
  37.             ),
  38.         ),
  39.     );
  40.    
  41.     $products = get_posts($args);
  42.    
  43.     var_dump($products); // Returns an array of products, but some products don't have the correct hair_colour or skin_tone etc...
Advertisement
Add Comment
Please, Sign In to add comment