Filter by ACF Field
-
I am trying to create a custom filter to find a custom post by a custom field value. Currently I have having trouble getting the GraphiQL IDE to return any results based on stopNumber in the following structure.
query QueryStop { sgstops(where: {stopNumber: 171}) { nodes { guideFields { stopNumber } id title } edges { node { slug title id content guideFields { stopNumber } } } } }
I have added the following code to my functions.php but I seem to be missing something. I based the code of the tutorial I found here. https://www.wpgraphql.com/2020/04/14/query-posts-based-on-advanced-custom-field-values-by-registering-a-custom-where-argument
add_filter('graphql_post_object_connection_query_args', function ($query_args, $source, $args, $context, $info) { $stop_id = $args['where']['stop_number']; if (isset($stop_id)) { $query_args['meta_query'] = [ [ 'key' => 'stop_number', 'value' => $stop_id, 'compare' => '=' ] ]; } return $query_args; }, 10, 5);
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Filter by ACF Field’ is closed to new replies.