Advertisement
Beee

customize uwpqsf output

Sep 18th, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. <?php
  2. // overwrite search plugin output
  3. function customize_ultimate_output($results , $arg, $id, $getdata ){
  4.     $sex            = $arg['meta_query'][1]['value'];
  5.     $sex_compare    = $arg['meta_query'][1]['compare'];
  6.     $age            = $arg['meta_query'][2]['value'];
  7.     $age_compare    = $arg['meta_query'][2]['compare'];
  8.     $city           = $arg['meta_query'][3]['value'];
  9.     $city_compare   = $arg['meta_query'][3]['compare'];
  10.     if ( isset($getdata['cmf'][3]['value']) ) {
  11.         $services   = $getdata['cmf'][3]['value']; // value = array()
  12.     } else {
  13.         $services = false;
  14.     }
  15.     $search_term    = $arg['s'];
  16.     $posts_per_page = $arg['posts_per_page'];
  17.     $post_type      = $arg['post_type'];
  18.     $post_status    = $arg['post_status'];
  19.     $orderby        = $arg['orderby'];
  20.     $order          = $arg['order'];
  21.     $meta_key       = $arg['meta_key'];
  22.     $meta_query     = array();
  23.     $tax_query      = array();
  24.     $compare        = '';
  25.  
  26.     $orderby    = false;
  27.     $paged      = false;
  28.     $meta_key   = NULL;
  29.  
  30.     $new_args = array(
  31.         'post_type'         => $post_type,
  32.         'posts_per_page'    => $posts_per_page,
  33.         'meta_key'          => $meta_key,
  34.         'orderby'           => $orderby,
  35.         'order'             => $order,
  36.         'paged'             => $paged,
  37.         'meta_query'        => array(
  38.             'relation'      => '',
  39.             array(
  40.                 'key'       => 'dvp_sex',
  41.                 'value'     => $sex,
  42.                 'compare'   => $sex_compare,
  43.             ),
  44.             array(
  45.                 'key'       => 'dvp_age',
  46.                 'value'     => $age,
  47.                 'compare'   => $age_compare,
  48.             ),
  49.             array(
  50.                 'key'       => 'dvp_city',
  51.                 'value'     => $city,
  52.                 'compare'   => $city_compare,
  53.             ),
  54.             array(
  55.                 'key'       => 'dvp_services',
  56.                 'value'     => $services,
  57.                 'compare'   => '='
  58.             ),
  59.         ),
  60.         's' => '',
  61.     );
  62.     // echo '<pre>'; var_dump($new_args); echo '</pre>';
  63.     // exit;
  64.  
  65.     // The (Original) Query
  66.     $apiclass   = new uwpqsfprocess();
  67.     $wp_query   = new WP_Query( $new_args );
  68.     ob_start();
  69.     $result     = '';
  70.  
  71.     // The Loop
  72.     if ( $wp_query->have_posts() ) :
  73.         $countquery = $wp_query->found_posts;
  74.         $what       = 'result';
  75.         if ( $countquery > 1 ) {
  76.             $what .= 's';
  77.         }
  78.  
  79.         echo '<p>We found '.$countquery.' ' . $what . ' matching your criteria.</p>';
  80.  
  81.         // echo $apiclass->ajax_pagination( $arg['paged'], $wp_query->max_num_pages, 10, $id, $getdata );
  82.  
  83.         // 2do: add list header
  84.  
  85.         while ( $wp_query->have_posts() ) : $wp_query->the_post();
  86.             echo '<p><a href="'.get_the_permalink().'">'.get_the_title().'</a></p>';
  87.         endwhile;
  88.  
  89.         // 2do: add list footer
  90.  
  91.         echo $apiclass->ajax_pagination( $arg['paged'], $wp_query->max_num_pages, 20, $id, $getdata );
  92.  
  93.     else : // if no posts
  94.         echo '<p>'; __('Nothing found', 'dvp'); echo '</p>';
  95.     endif;
  96.  
  97.     /* Restore original Post Data */
  98.     wp_reset_postdata();
  99.     $results = ob_get_clean();
  100.     return $results;
  101. }
  102. add_filter('uwpqsf_result_tempt', 'customize_ultimate_output', '', 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement