Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $search = sanitize_text_field($_POST['s']);
- $region = (isset($_POST['region']) ? sanitize_text_field($_POST['region']) : '' );
- $post_type = sanitize_text_field($_POST['post_type']);
- $activite = array();
- foreach($_POST as $p => $i){
- if(strpos($p,'activite') !== false){
- array_push($activite, $i);
- }
- }
- $service = array();
- foreach($_POST as $p => $i){
- if(strpos($p,'service') !== false){
- array_push($service, $i);
- }
- }
- //echo $search . PHP_EOL . $region . PHP_EOL . $activite . PHP_EOL . $service . PHP_EOL;
- $args = array(
- 'post_type' => $post_type,
- 's' => $search,
- 'order' => 'asc',
- 'orderby' => 'title',
- 'posts_per_page' => '-1',
- 'tax_query' => array('relation' => 'AND')
- );
- if($region != ''){
- array_push($args['tax_query'], array('taxonomy' => 'region',
- 'field' => 'slug',
- 'terms' => $region)
- );
- }
- // These are the faulty taxonomies
- if(count($activite) > 0){
- array_push($args['tax_query'], array('taxonomy' => 'activite',
- 'field' => 'slug',
- 'terms' => $activite,
- 'operator' => 'IN'));
- }
- if(count($service) > 0){
- array_push($args['tax_query'], array('taxonomy' => 'service',
- 'field' => 'slug',
- 'terms' => $service));
- }
- $query = new WP_Query( $args );
- $results = $query->get_posts();
- -------------------------------------
- Args dump with 1 param checked
- array(6) {
- ["post_type"]=>
- string(8) "vignoble"
- ["s"]=>
- string(0) ""
- ["order"]=>
- string(3) "asc"
- ["orderby"]=>
- string(5) "title"
- ["posts_per_page"]=>
- string(2) "-1"
- ["tax_query"]=>
- array(2) {
- ["relation"]=>
- string(3) "AND"
- [0]=>
- array(4) {
- ["taxonomy"]=>
- string(8) "activite"
- ["field"]=>
- string(4) "slug"
- ["terms"]=>
- array(1) {
- [0]=>
- string(9) "activite1"
- }
- ["operator"]=>
- string(2) "IN"
- }
- }
- }
- --------------------------------------
- Args dump with 2 params
- array(6) {
- ["post_type"]=>
- string(8) "vignoble"
- ["s"]=>
- string(0) ""
- ["order"]=>
- string(3) "asc"
- ["orderby"]=>
- string(5) "title"
- ["posts_per_page"]=>
- string(2) "-1"
- ["tax_query"]=>
- array(2) {
- ["relation"]=>
- string(3) "AND"
- [0]=>
- array(4) {
- ["taxonomy"]=>
- string(8) "activite"
- ["field"]=>
- string(4) "slug"
- ["terms"]=>
- array(2) {
- [0]=>
- string(9) "activite1"
- [1]=>
- string(9) "activite2"
- }
- ["operator"]=>
- string(2) "IN"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement