Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

ACF Format Value Filters are ignored by WPGraphQL ACF #192

Closed
nhankla-kl opened this issue Dec 17, 2020 · 2 comments
Closed

ACF Format Value Filters are ignored by WPGraphQL ACF #192

nhankla-kl opened this issue Dec 17, 2020 · 2 comments

Comments

@nhankla-kl
Copy link

nhankla-kl commented Dec 17, 2020

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!

@michaelpanik
Copy link

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

@jasonbahl jasonbahl assigned jasonbahl and unassigned jasonbahl Mar 5, 2021
jasonbahl added a commit that referenced this issue Sep 15, 2022
…ue-filters-are-ignored-by-wpgraphql-acf

filter returned value with acf/format_value
jasonbahl added a commit that referenced this issue Sep 16, 2022
…t-value-filters-are-ignored-by-wpgraphql-acf

Revert "filter returned value with acf/format_value"
@jasonbahl
Copy link
Contributor

Some history: #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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants