Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to meta_query with meta values as serialize arrays #189

Open
huynhlongdev opened this issue Apr 28, 2024 · 2 comments
Open

How to meta_query with meta values as serialize arrays #189

huynhlongdev opened this issue Apr 28, 2024 · 2 comments

Comments

@huynhlongdev
Copy link

$prefix = 'listing_options_';
CSF::createMetabox($prefix, array(
'title' => 'Options',
'post_type' => 'featured-listings',
'data_type' => 'serialize'
));
CSF::createSection($prefix, array(
'fields' => array(
array(
'id' => $prefix . 'types',
'type' => 'select',
'title' => 'Types',
'placeholder' => 'Select an option',
'options' => array(
'residential' => 'residential',
'land' => 'Land',
'lease' => 'Lease',
),
'default' => 'residential'
),
)
));

I used but code not working
$args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => 'listing_options_types',
'value' => $cat,
'compare' => 'LIKE', // or =
),
);

@LC43
Copy link
Contributor

LC43 commented Jun 18, 2024

You shouldn't. You'll have to expose the meta in a individual field.

Serialized only the content meta, and break all the fields that are going to be used in search individually.

@huynhlongdev
Copy link
Author

You can't. You'll have to expose the meta in a individual field.

Serialized only the content meta, and break all the fields that are going to be used in search individually.

$args['meta_query'] = array(
	'relation' => 'AND',
	array(
		'key' => 'listing_options_',
		'value' => sprintf(':"%s";', $settings['meta_key']),
		'compare' => 'LIKE'
	),
);

I tried and the code worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants