Filter by meta key/value
-
I am trying to filter by meta and not having much luck. I have been able to filter the order, post count and other things. This is for a custom post type, so not sure if that is the issue.
This is what I am trying to use, filter my meta_key of artist and meta_value of the artists ID.
/wp-json.php/posts?type=artwork&filter[meta_key]=artist&filter[meta_value]=264I also read about allow public meta, so tested adding the below code as the custom meta/fields are form advanced custom fields.
add_filter( 'rest_api_allowed_public_metadata', 'jeherve_allow_fb_metadata' ); function jeherve_allow_fb_metadata() { // only run for REST API requests if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST ) return $allowed_meta_keys; $allowed_meta_keys[] = '_artist'; $allowed_meta_keys[] = 'artist'; return $allowed_meta_keys; }
Cheers!
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Filter by meta key/value’ is closed to new replies.