WPML

Overview of the Issue

When using GraphQL and utilizing a query similar to the following to retrieve Custom Post Types by slug, you will discover that it functions only for the posts in the default language:

query getArticlesByslug {

  article(id: "your-slug-goes-here", idType: SLUG) {

    title

    content

  }

}

Workaround

This issue is fixed in WPML GraphQL 1.2.0. Updating solves it on your site, so you only need this workaround if you can’t update yet.

Update to WPML GraphQL 1.2.0 or later. Queries by slug now return custom posts in every language, and you do not need the code below.

If you cannot update yet:

Please, make sure of having a full backup of your site before proceeding.
  • Open your theme’s functions.php file.
  • Add this code:
    add_filter('request', function($vars){
    
    	if ( is_graphql_http_request() && !empty($vars['name']) ) {
    		$vars['suppress_filters'] = true;
    	}
    
    	return $vars;
    });

All known issues

Still Seeing This Issue?

If updating doesn’t fix it, ask a support question and we’ll look into it with you.