I am trying to add a new filter for a custom field defined with the Advanced Custom Fields plugin.
I want to filter on the age of artists, I looked up some documentation but got confused in the progress. (I am a wordpress newbie)
I have added the following lines of code to my functions.php, sadly without any noticable results.
add_action('graphql_register_types', function () {
$customposttype_graphql_single_name = "artist";
register_graphql_field('RootQueryTo' . $customposttype_graphql_single_name . 'ConnectionWhereArgs', 'age', [
'type' => 'ID',
'description' => __('The ID of the post object to filter by', 'your-textdomain'),
]);
});
add_filter('graphql_post_object_connection_query_args', function ($query_args, $source, $args, $context, $info) {
$post_object_id = $args['where']['age'];
if (isset($post_object_id)) {
$query_args['meta_query'] = [
[
'key' => 'artist_metadata',
'value' => $post_object_id,
'compare' => '='
]
];
}
return $query_args;
}, 10, 5);
What I wish to achieve is to filter artists on the age field which is in the artist_metadata field group defined by Advanced Custom Fields, image below for clarification.