Saltar navegación

Open

Reported for: WPML GraphQL 1.0.0

Topic Tags: Bug, Compatibility

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

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;
    });
    

9 respuestas para “WPML GraphQL - Fails to Fetch Single Custom Post Type by Slug Based”

  1. We are are also experiencing this problem.
    We have a custom post type called «Teacher» – the URI for a specific teacher is «/underviser/karsten-lund/» in danish, and «/en/teacher/karsten-lund/» in english.
    When i query the contentNode by using:
    contentNode(id: «/underviser/karsten-lund/», idType: URI) {
    id
    }

    I get the expected teacher
    But if i query:
    contentNode(id: «/en/teacher/karsten-lund/», idType: URI) {
    id
    }

    I get null.

  2. Hi Andrés and WPML team,

    The workaround work for me but I got another problem:

    Below is my current query:
    «`
    query GetPostBySlug($slug: ID!) {
    post(id: $slug, idType: URI) {
    title
    }
    }
    «`

    When I’m querying with second language, I got the same result:
    «`
    query GetPostBySlug {
    post(id: «/vi/hello-world/», idType: URI) {
    title
    }
    }
    «`

    Result:
    «`
    «data»: {
    «post»: {
    «title»: «The journey has just started!»
    }
    }
    «`

    Expeceted result:
    «`
    «data»: {
    «post»: {
    «title»: «Hanh trinh moi bat dau»
    }
    }
    «`

Deje una respuesta

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

Puede utilizar estas etiquetas:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>