Skip Navigation

[Resolved] How can I use meta_query with toolset checkbox custom field?

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by alixB 5 years, 5 months ago.

Author
Posts
#1308837

Hello,

I'm trying to make a WP_Query where I want to display specifics posts.
Nothing complicated, it's quite easy with WordPress.

But I have a problem with the way Toolset stores checkbox data (it's serialized)

In toolset, my custom fields "Visibility" are 3 checkboxes: "Public" "Member only" and "Admin".

If, the "public" checkbox is checked then I display it (as my query is forged).

add_action( 'elementor/query/homepage_communication', function( $query ) {
	$query->set( 'post_status', [ 'publish' ] );
	$query->set( 'post_type', [ 'communication' ] );
	$query->set( 'meta_query', [ ['compare' => 'IN', 'key' => 'wpcf-communication_visibility', 'value' => 'public'] ] );
} );

But, the meta data looks like this :

  ["wpcf-communication_visibility"]=>
  array(1) {
    [0]=>
    string(197) "a:2:{s:64:"wpcf-fields-checkboxes-option-5cea2076154a49b3683901cdc9174e3f-1";a:1:{i:0;s:6:"public";}s:64:"wpcf-fields-checkboxes-option-af4d6c8d37c4e8781e6ca35aae024344-1";a:1:{i:0;s:7:"members";}}"
  }

So, i'm not sure how to use the meta_query with theses data.. Any help?

#1308841

I used "LIKE" to compare and it seems to work.