Advertisement
Guest User

Untitled

a guest
Sep 30th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. $args = array();
  2.     $args['s'] = $_REQUEST['search'];
  3.     $args['tax_query'] = array( 'relation' => 'AND' );
  4.     $args['meta_query'] = array(
  5.         'relation' => 'OR',
  6.         array(
  7.             array(
  8.                 'key' => 'pt_assessment',
  9.                 'value' => 'rebel',
  10.                 'compare' => 'LIKE'
  11.             ),
  12.         ),
  13.         array( 'relation' => 'AND' ),
  14.     );
  15.  
  16.     // collect filter data
  17.     // apply post types
  18.     if ( array_key_exists( 'types', $_REQUEST ) && is_array( $_REQUEST['types'] ) && count( $_REQUEST['types'] ) > 0 ) {
  19.         $args['post_type'] = $_REQUEST['types'];
  20.     }
  21.  
  22.     // apply grade filter (if any)
  23.     if ( array_key_exists('grade', $_POST) && strlen( $_POST['grade'] ) > 0 ) {
  24.         $args['meta_query'][1][] = array(
  25.             'key' => 'pt_grade_level',
  26.             'value' => $_POST['grade'],
  27.             'compare' => '=',
  28.         );
  29.     }
  30.  
  31.     // apply content area filter (if any)
  32.     if ( array_key_exists('contentArea', $_POST) && strlen( $_POST['contentArea'] ) > 0 ) {
  33.         $args['meta_query'][1][] = array(
  34.             'key' => 'pt_content_area',
  35.             'value' => serialize( strval( $_POST['contentArea'] ) ),
  36.             'compare' => 'LIKE',
  37.         );
  38.     }
  39.  
  40.     // apply standard filter (if any)
  41.     if ( array_key_exists('standard', $_POST) && strlen( $_POST['standard'] ) > 0 ) {
  42.         $args['meta_query'][1][] = array(
  43.             'key' => 'pt_standard',
  44.             'value' => $_POST['standard'],
  45.             'compare' => '=',
  46.         );
  47.     }
  48.  
  49.     // apply PD Course taxonomy filter (if any)
  50.     if ( array_key_exists('pdCourse', $_POST) && strlen( $_POST['pdCourse'] ) > 0 ) {
  51.         $args['tax_query'][] = array(
  52.             'taxonomy' => 'pd_courses',
  53.             'field' => 'id',
  54.             'terms' => $_POST['pdCourse'],
  55.             'operator' => 'IN',
  56.         );
  57.     }
  58.  
  59.     $loop = new WP_Query( $args );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement