Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 1 year, 2 months ago.

Assisted by: Nigel.

Author Posts
August 22, 2023 at 8:08 am #14268651

bjarteL

Hi there!

I have seen your solution regarding query a post by slug with graphql in this post: https://wpml.org/forums/topic/unable-to-query-a-post-by-a-slug-with-graphql/

It only works on graphql IDE, not on actual endpoint (hidden link) which still return null.

Could you please help on this? Thanks.

August 23, 2023 at 1:16 pm #14278597

Nigel
Supporter

Timezone: Europe/Madrid (GMT+01:00)

Hi there

I've been trying this out on my own local setup to test headless WordPress, and I found something similar, where the workaround provided in the other ticket didn't work for requests from the headless site, even though it appeared to work with the GraphQL IDE in the WordPress back end.

I tried a few alternatives and came up with this, which worked on my site, could you please check the same?

add_filter('request', function($vars){

	if ( is_graphql_http_request() && !empty($vars['name']) ) {
		$vars['suppress_filters'] = true;
	}

	return $vars;
});

The intention is the same: if a GraphQL request passes the post slug then the WPML filters that normally handle returning posts in different languages are disabled.

August 29, 2023 at 9:01 am #14305555

bjarteL

It is working as expected. Thank you.