Checkbox field is stored as serialized array, therefore you can not use the IN
operator and array with the values you are looking for.
To get posts with checked “melbourne”, change meta_query
to:
$meta_query = array(
array(
'key' => $name,
'value' => '"melbourne"',
'compare' => 'LIKE',
)
);
To get posts with melbourne
or sydney
:
$meta_query = array(
'relation' => 'OR',
[
'key' => $name,
'value' => '"melbourne"',
'compare' => 'LIKE',
],
[
'key' => $name,
'value' => '"sydney"',
'compare' => 'LIKE',
],
);
Think about changing the solution, because these types of queries negatively affect performance.
Related Posts:
- Filtering a WP_Query meta_query by numeric values isn’t working
- filter search result with custom post type meta key
- List events by month
- Can’t sort order of wp_query with 2 meta keys
- Show ACF field from custom taxonomy and display on the single template
- Change message given when deleting post from custom post type
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Link users to a custom post type
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- get_posts of Custom Post Type AND Custom Taxonomy
- WP_Query to select custom post type with Advanced Custom Fields (ACF) date
- Stuck in Order by more then one
- Meta Query Not Returning Output Despite Having Matching Values
- search suggest – filter post type
- How to update post meta on uploaded image from a custom form?
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Displaying custom field according to date
- Query based on custom fields start and end date
- Create short URL with auto 301 redirect
- Query entries from custom post type in an ACF flexible content field
- meta query not retrieving posts
- Using WP meta query to show custom post types by a start and finish date
- Fetch data from two custom post types and create multidimensional array for output to html table
- Custom front-end form for adding post – Category problem
- count & sum the value of custom field of the author post in dynamic posts
- Grouping custom wordpress post types by acf value
- Filter result of Custom Post Type using meta_query with ACF
- WordPress – display relationship between blog posts and custom posts
- Query posts by current ACF meta key value on single page as related posts
- Custom sorting in post columns by ACF Pro Select Field
- Load info from customposttype into template page
- ACF meta_key and meta_value break loop
- Display Specific Posts at Start of Loop
- How to get the posts that my following users are liked?
- CPT: execute code after load if parameter is set
- ACF Post Content Not Being Searched
- Display related post content and custom field content
- Meta query broken since 4.7.4 Update
- Group/list/sort custom post type posts by date in tabs from acf datepicker field
- Can’t pick up a field created with Advanced Custom Fields
- Custom post tag images not displaying with ACF
- Get month and day from a Date Picker custom field
- using ACF datepicker to filter posts on a page
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Trying to combine multiple WordPress queries
- Custom Post-type not returning the right child_of
- Getting ACF relationship field information
- How to I add count of custom posts listed in a post as a prefix to its title
- Display two post types ordered by two custom fields
- Displaying custom post type on category pages but not on blog listings
- pre get posts changing the query
- How loop through posts based on custom fields
- Get Custom Field Values by Another Custom Field in WordPress
- is_page_template not working as expected
- Create a random unique 6 digit number as custom field for custom post type
- Loading all files within a directory
- Custom Post Types not showing, custom WP_Query
- advanced search forms with 3 input text and that the main problem 3 input text
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- How to alter WP-JSON main query or best practise for custom endpoints
- Cluster CPT posts to users based on ACF value from their profile on dashboard
- ACF Values Don’t Show After Import Unless I Edit/Update Post
- Query Custom Post Type Taxonomy term with multiple parameters
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to group posts and get a mixed posts and groups view?
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- How to Output which matched meta_keys were found from custom_type_posts?
- How to let users choose where to search for posts?
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- Why is my WP Query not returning first result’s post meta?
- WP_Query Custom Post Type if Category ID Equals
- Control content before and after custom post type loop
- How to use a variable as a function name?
- How do I create a new post upon registration with the users first and last name as title
- Distribute Custom Post in different pages
- How do I replace the post title with a custom field?
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Using page title as a link to term archive
- pagination for custom post type archive page
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Archive page for WordPress Custom Post Type doesn’t show pagination from paginate_links()
- Is it possible to get the specific content on the search page?
- Create/populate Custom Posts ACF fields from external JSON file
- WordPress URL rewrites using Advanced Custom Field
- Custom Post Type and Structure Question
- How to select meta key in custom database query
- How to access repeater field of a custom field?
- Do not show child pages within a file page
- Search result based on URL
- Display custom tax in “while” loop
- Show custom taxonomy not in submenu
- Events with multiple event dates + permalink for each date
- pre_get_posts not firing at all
- Function not pulling image or text from custom post type
- Copying custom field value in to title
- Pagination not working on homepage
- How do I filter a custom post type loop by a field?
- ACF Relationship: Group posts by parent category term, then child [closed]
- How to manage wordpress knowledge base/wiki/posts collections
- Issue displaying multiple TinyMCE editors with WPAlchemy