Skip Navigation

[Resolved] Query on checkboxes field

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 3 voices.

Last updated by Minesh 7 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#529942

I am trying to create a form search with select options
I get value of option but i have problem with query on multi checkboxs:

array(
'relation' => 'OR',
array(
'key' =>wpcf-size,
'value' => $_GET['size'],
'compare' => 'LIKE'
)
)

the problem is that wpcf-size is array...

#529951

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leon,

Thank you for contacting our support forum.

Could you try using IN instead of LIKE.

Take a look at this example

array(
			'key'     => 'age',
			'value'   => array( 3, 4 ),
			'compare' => 'IN',
		),

Please let me know if this helps.
Thanks,
Shane

#530504

Hi, thank you but not work,
key is array checkboxes
value is a single value

#530579

This is my complete code:

echo '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/'  ) ) . '">
echo'<select name="size" class="dropdown"> 
<option value="all">All</option>';
global $wpdb;
$values2 = $wpdb->get_col("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key ='wpcf-size'" );
foreach( $values2 as $valore2)  {
$opzioni2[]=(unserialize($valore2));
	}
array_walk_recursive($opzioni2, function ($value, $key) use (&$list2) {
   $list2[] = $value;
});
foreach( array_unique ($list2) as $valore2)  {
echo '<option value="'.$valore2.'">'.$valore2.'</option><br>';
}
echo'</select></form>';

and this is a query

$meta_query[] = array(
		   array(
 array(
  'relation' => 'OR',
												    array(
		'key'       => 'wpcf-size',
		'value'   => $_GET['size'],
    'compare' => 'IN'
				)	
)
				)
				);
#530858

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please try to use meta_compare => 'LIKE' in the parameters.

For example:

$meta_query[] = array(
           array(
 array(
  'relation' => 'OR',
                                                    array(
        'key'       => 'wpcf-size',
        'value'   => $_GET['size'],
    'compare' => 'LIKE'
                )   )));

More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

#531095

Sorry but not work.
I have create a post child with a multicheckboxes field called 'size' (wpcf-size).
Post child of products woocommerce.
I want display all product with a selected size for example 12,40.
I have create this function

add_action( 'woocommerce_product_query', 'so_27971630_product_query' );

function so_27971630_product_query( $q ){

    $meta_query = $q->get( 'meta_query' );

$meta_query[] = array(
           array(
 array(
  'relation' => 'OR',
                                                    array(
        'key'       => 'wpcf-size',
        'value'   => $_GET['size'],
    'compare' => 'IN'
                )   
)
                )
                );

$q->set( 'meta_query', $meta_query );
}
#531311

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can I have problem URL and access details?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

The forum ‘Types Community Support’ is closed to new topics and replies.