Advertisement
wzislam

Advanced Search WP_Query()

Aug 11th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2.         /*
  3.         *   GET ALL THE QUERY VARIABLES ($_GET[])
  4.         */
  5.  
  6.         $name = $_GET['name'] != '' ? $_GET['name'] : '';
  7.         $passport = $_GET['passport'] != '' ? $_GET['passport'] : '';
  8.         $h_id = $_GET['h_id'] != '' ? $_GET['h_id'] : '';
  9.         $father_husband = $_GET['father_husband'] != '' ? $_GET['father_husband'] : '';
  10.         $mother = $_GET['mother'] != '' ? $_GET['mother'] : '';
  11.         $location_id = $_GET['locations'] != '' ? $_GET['locations'] : '';
  12.         $age_range = $_GET['age'];
  13.  
  14.         $age_array = explode('-', $age_range);
  15.  
  16.         $args = array(
  17.                 //'post_type'       => array( 'hajji', 'flights', 'moallem' ),
  18.                 'post_type'         => 'hajji',
  19.                 'post_status'       => 'publish',
  20.                 's'                 => $name,
  21.                 'tax_query'         => array(
  22.                                         array(
  23.                                             'taxonomy' => 'locations',
  24.                                             'field'    => 'id',
  25.                                             'terms' => $location_id
  26.                                         ),
  27.                 ),
  28.                 'meta_query'        => array(
  29.                                             'relation' => 'OR',
  30.                                             array(
  31.                                                 'key' => 'hajji_id',
  32.                                                 'value'   => $h_id,
  33.                                                 'type'    => 'numeric',
  34.                                                 'compare' => '=',
  35.                                             ),
  36.                                             array(
  37.                                                 'key' => 'hajji_father_husband',
  38.                                                 'value'   => $father_husband,
  39.                                                 'type'    => 'CHAR',
  40.                                                 'compare' => '=',
  41.                                             ),
  42.                                             array(
  43.                                                 'key' => 'hajji_mother',
  44.                                                 'value'   => $mother,
  45.                                                 'type'    => 'CHAR',
  46.                                                 'compare' => '=',
  47.                                             )
  48.                                     )
  49.                        
  50.                 );
  51.  
  52.         $hajji_query = new WP_Query( $args );
  53.  
  54.  var_dump($hajji_query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement