I got that working 🙂
add_filter('rest_myRoute_query', function($args, $request) {
$fields = array('myCustomField');
foreach ($fields as $field) {
if (! empty($request[$field])) {
$args['meta_query'][] = array(
'key' => $field,
'value' => esc_sql($request[$field]),
);
}
}
return $args;
}, 10, 2);
Related Posts:
- Search multiple custom fields by using meta_query
- WP_Query orderby custom field then post_date in one query
- Filtering a WP_Query meta_query by numeric values isn’t working
- Sorting a query by custom field date
- How can I generate a RSS feed based on a custom WP_Query?
- Display Custom Post Type Fields
- Search Custom Post Type with all meta attached?
- How to sort CPT by custom meta value (date), and return posts month by month
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- WordPress query by multiple Custom fields and order by date
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Get post info inside modal window?
- Having trouble with custom date field for CPT query (WordPress)
- How to add custom fields to admin UI and REST API response?
- Display posts if a custom field value is equal to another custom field value
- Sort by two dates. Default entry date and custom field if present
- Conditional to modify query results
- Filtering by Post Meta Custom Fields – Performance
- wp_query to find posts by year and month
- WP Query—Relationship between two custom post types and their fields
- Get all Posts If has same custom field values in Posts
- is_main_query() not working for WP REST API
- Including Custom Meta with posts_where query
- WP_Query: include custom post type only with specific meta value
- WP_Query orderby modified to include custom meta changes
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- How can I get the number of custom post type posts that have a specific attachment image set?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- Callback to custom field is not working in WordPress REST API
- Including metaboxes from custom post types in global search — continued
- Query Multiple Custom Posts by Custom Fields
- filter custom post in rest api with custom function
- Get Posts by multiple custom fields is not working
- Order Custom Post Type by Custom Field Value
- Custom REST endpoints for a custom post type with custom fields
- Possible to filter custom post type with multiple meta data?
- Query based on custom fields start and end date
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Create custom post with meta field with AJAX and the WordPress REST API
- WP Query ‘posts_per_page’
- Display post from a date range from custom field
- post_per_page ignored in WP_Query
- How to get specific post meta by title or id
- Getting a custom post’s custom field based on another custom post’s custom field select
- WP_Query orderby not work with meta_key
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Display custom post type for specific user
- Custom Post type loop with ACF not displaying properly
- Cache issue with WP_Query and custom field filtering
- How do I list a custom field and custom taxonomies for each result in a loop?
- How to make an API call to a custom post type but filtering by meta value?
- WP query_posts group by meta field related
- Custom Form / Search with Custom Post Type Data
- Create if else for post types in WP_Query ‘post__in’ values
- WP Query from two Custom Post type fields as statement
- Alike Shortcode using in Custom Shortcode
- Query custom post type that has a serialized relational advanced custom field value
- How To Read Read Custom Post Type Data in Headless CMS Mode
- WP_Query: how to search tags in addition to a custom post type?
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Sort custom post column by generated value?
- How can I query and sort custom-post type using WP_Query
- Filter posts by their related field’s custom field
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- register_rest_field update_callback don’t work for $_FILES
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- Post Filtered by Custom Field Value
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- filter rest api post by a acf filed
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- sorting in wp query based on custom field value
- Meta_Query refuses to return results
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Error in WP Query. If variable is empty it is displaying previous post value
- Query events post type after current date and timezone
- Calling specific page with wp query
- How to stop wp_query searching pages as well as the specified CPT
- WP_Query and two custom fields returns no posts
- WP_Query get posts where post_name is empty
- Storing/querying custom date data
- 404 on Pages for Custom Post Type & Query_Posts
- Querying meta values within an array
- Filter Custom post type by another Custom post type
- Show Posts in Vertical Tabs with Scrollbar
- How to show all posts of specific custom post type with their custom fields values?
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Sort CPT by taxonomy AND THEN by custom field
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- Query order by a numeric ACF field