• Hello

    I try to make a wp_query with types checkboxes in an ajax request by doing this

    on the front I load the checkboxes in a form :

    function get_cb(){
    
    	$output = "";
    	$cb = get_option('wpcf-fields');
    	$unz = $sptes['my_checkboxes']['data']['options'];
    
    	foreach($unz as $k => $v1)
    	{
    		if (isset($v1['title'])) {
        		$output .= "<input name='my_cbs' type='checkboxes' value='".$v1['set_value']."'>".$v1['title'];
    		}
    	}
    	echo json_encode($output);
    	die;
    }

    Once the form is submitted, I want to compare selected checkboxes with database :

    function compare(){
    
       $checkboxes= $_REQUEST['my_cbs'];
       $output = "<h2>Résults :</h2>";
    
    	$args = array(
    		'post_type' => 'my_custom_post_type',
    		'posts_per_page' =>10,
    		'meta_query' => array(
    			'relation' => 'AND'
    			)
    		);
    		$args['meta_query'][] = array('key' => 'wpcf-my_checkboxes' , 'value' => $equipements, 'compare' => 'IN');
    
    	$query = new WP_Query( $args );
    }

    So it does’nt work. someone could guide me ?
    Thanks a lot

    https://ww.wp.xz.cn/plugins/types/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Dear nspace1999

    Are you sure this data is saved in database? Did you check this in post_meta table?

    I ask, because yo do not show code to save.

    Marcin

    Thread Starter nspace1999

    (@nspace1999)

    Hello

    The data are correctly stored in database. I think my code does not work beacause the values are serialized in database.
    Am I right ?

    Dear nspace1999

    Yes. Right! Checkboxes are stored as a serialised array.

    Then you can use this field for query 🙁

    Could you create a few checkbox field instead checkboxes field?

    Marcin

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_query with types checkboxes’ is closed to new replies.