wp-graphql-acf icon indicating copy to clipboard operation
wp-graphql-acf copied to clipboard

ACF Format Value Filters are ignored by WPGraphQL ACF

Open nhankla-kl opened this issue 4 years ago • 1 comments

Hello, Trying to modify the link URL value to be relative links. This way we can work locally using the same dev database. The issue is WPGraphQL ACF is ignoring the stand acf/format_value filter https://www.advancedcustomfields.com/resources/acf-format_value/

code in theme file:

function my_acf_format_link_field( $value, $post_id, $field ) {
if(is_array($value)){
		$site_url = get_site_url();
		$value['url'] = str_replace($site_url, '', $value['url']);
	}
	return $value;
}
add_filter('acf/format_value/type=link', 'my_acf_format_link_field',100,3);

This works as expected in a native wordpress site. It strips out the site_url and returns a relative link.

Thanks for the help and great plugin!

nhankla-kl avatar Dec 17 '20 19:12 nhankla-kl

I'm running into this issue as well. Any updates or thoughts?

michaelpanik avatar Feb 16 '21 16:02 michaelpanik

Some history: https://github.com/wp-graphql/wp-graphql-acf/pull/336

We merged this feature in the past, then reverted it because it causes other problems.

ACF can return differently formatted values for a field (i.e. sometimes it will return an ID, sometimes an object, etc), but for ACF we have to return strongly typed values. i.e. an object always needs to be an object, a string always needs to be a string, etc.

Because of that, we can't centrally support this filter.

In the new version of WPGraphQL for ACF (see: https://github.com/wp-graphql/wpgraphql-acf) you could use this filter: wpgraphql/acf/field_value (see: https://github.com/wp-graphql/wpgraphql-acf/blob/main/src/FieldConfig.php#L446) to accomplish something similar.

jasonbahl avatar Oct 30 '23 18:10 jasonbahl