Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 451 characters in body
Source Link
Adi
  • 340
  • 2
  • 9
  • 23

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName)
                            
                            ) 
            );

But the problemThe checkbox html is that thisgenerated by jquery which is not working for

jQuery('#state_div').append('<label><input type="checkbox" name="stateName['+ state_arr[x] +']" id="" value="'+ state_arr[x] +'" >' + state_arr[x] + '</label');

So the name of the input is a array it self, which give me values like this

stateName[cityname1];
stateName[cityname2];
stateName[cityname3];
stateName[cityname4];

and so on. So any suggestionsomeone tell me wether i am using right way to get these data or make correct query or not. Thanks

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName)
                            
                            ) 
            );

But the problem is that this is not working for me. So any suggestion. Thanks

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName)
                            
                            ) 
            );

The checkbox html is generated by jquery which is

jQuery('#state_div').append('<label><input type="checkbox" name="stateName['+ state_arr[x] +']" id="" value="'+ state_arr[x] +'" >' + state_arr[x] + '</label');

So the name of the input is a array it self, which give me values like this

stateName[cityname1];
stateName[cityname2];
stateName[cityname3];
stateName[cityname4];

and so on. So someone tell me wether i am using right way to get these data or make correct query or not. Thanks

deleted 17 characters in body
Source Link
Adi
  • 340
  • 2
  • 9
  • 23

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName),
                            'compare' => '='
                            ) 
            );

But the problem is that this is not working for me. So any suggestion. Thanks

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName),
                            'compare' => '='
                            ) 
            );

But the problem is that this is not working for me. So any suggestion. Thanks

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName)
                            
                            ) 
            );

But the problem is that this is not working for me. So any suggestion. Thanks

Source Link
Adi
  • 340
  • 2
  • 9
  • 23

How we filter the search base on post-meta tags

I am using my custom filter. So in this search there are many checkboxes (have city name) and user selected some of them the post show the search result base on the checkbox. First i sotre the city/state name by using the add_post_meta

add_post_meta($post_id, 'post_state' , $state, true);

So after that when user filter the post. i am using the code

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'sortbydestination' ) :
$stateName = $_POST['stateName'];

unset($_POST);
endif;
$args = array(
            'posts_per_page' => 30,
            'paged' => $paged, 
            'post_type' => 'post', 
            'post_status' => 'publish',
            'meta_query' => array(
                            'key' => 'post_state',
                            'value' => array($stateName),
                            'compare' => '='
                            ) 
            );

But the problem is that this is not working for me. So any suggestion. Thanks