• Resolved priteshsaxena31

    (@priteshsaxena31)


    Hello Team

    I have created a translated website using GraphQL and WPML.

    I have created a custom post type with a custom taxonomy and translated that in french language.

    So when i fetched the posts based on taxonomy in GraphQL IDE it fetches the same language posts in both the posts weather it is English or french.

    What i want is if i select the english taxonomy it needs to fetch english posts and if i select french taxonomy it needs to fetch french posts.

    Can you provide a solution as to why this is happening?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter priteshsaxena31

    (@priteshsaxena31)

    I have checked the database it saves correct value for english and french

    Query are :

    english query :

    query NewQuery {
    city(id: "dGVybToxNDM=", idType: ID) {
    id
    slug
    languageCode
    translations {
    id
    }
    models {
    edges {
    node {
    slug
    languageCode
    databaseId
    }
    }
    }
    posts {
    edges {
    node {
    id
    languageCode
    }
    }
    }
    }
    }
    result of english query :

    {
    "data": {
    "city": {
    "id": "dGVybToxNDM=",
    "slug": "belgium",
    "languageCode": "en",
    "translations": [
    {
    "id": "dGVybTo4NjI2"
    }
    ],
    "models": {
    "edges": [
    {
    "node": {
    "slug": "phaedra",
    "languageCode": "en",
    "databaseId": 59387
    }
    },
    {
    "node": {
    "slug": "valentina",
    "languageCode": "en",
    "databaseId": 59282
    }
    },
    {
    "node": {
    "slug": "caroline",
    "languageCode": "en",
    "databaseId": 58213
    }
    },
    {
    "node": {
    "slug": "angelina",
    "languageCode": "en",
    "databaseId": 58052
    }
    },
    {
    "node": {
    "slug": "emily",
    "languageCode": "en",
    "databaseId": 57712
    }
    },
    {
    "node": {
    "slug": "lisa",
    "languageCode": "en",
    "databaseId": 57502
    }
    },
    {
    "node": {
    "slug": "julia",
    "languageCode": "en",
    "databaseId": 55700
    }
    },
    {
    "node": {
    "slug": "isabelle",
    "languageCode": "en",
    "databaseId": 5742
    }
    },
    {
    "node": {
    "slug": "iris",
    "languageCode": "en",
    "databaseId": 3151
    }
    },
    {
    "node": {
    "slug": "alice",
    "languageCode": "en",
    "databaseId": 233
    }
    }
    ]
    },
    "posts": {
    "edges": [
    {
    "node": {
    "id": "cG9zdDo1ODU4NQ==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1ODM4OQ==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1NzgwOA==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1MjYy",
    "languageCode": "en"
    }
    }
    ]
    }
    }
    }
    }

    french query :

    query NewQuery {
    city(id: "dGVybTo4NjI2", idType: ID) {
    id
    slug
    languageCode
    translations {
    id
    }
    models {
    edges {
    node {
    slug
    languageCode
    databaseId
    }
    }
    }
    posts {
    edges {
    node {
    id
    languageCode
    }
    }
    }
    }
    }

    result of french query:

    {
    "data": {
    "city": {
    "id": "dGVybTo4NjI2",
    "slug": "belgium-fr",
    "languageCode": "fr",
    "translations": [
    {
    "id": "dGVybToxNDM="
    }
    ],
    "models": {
    "edges": [
    {
    "node": {
    "slug": "phaedra",
    "languageCode": "en",
    "databaseId": 59387
    }
    },
    {
    "node": {
    "slug": "valentina",
    "languageCode": "en",
    "databaseId": 59282
    }
    },
    {
    "node": {
    "slug": "caroline",
    "languageCode": "en",
    "databaseId": 58213
    }
    },
    {
    "node": {
    "slug": "angelina",
    "languageCode": "en",
    "databaseId": 58052
    }
    },
    {
    "node": {
    "slug": "emily",
    "languageCode": "en",
    "databaseId": 57712
    }
    },
    {
    "node": {
    "slug": "lisa",
    "languageCode": "en",
    "databaseId": 57502
    }
    },
    {
    "node": {
    "slug": "julia",
    "languageCode": "en",
    "databaseId": 55700
    }
    },
    {
    "node": {
    "slug": "isabelle",
    "languageCode": "en",
    "databaseId": 5742
    }
    },
    {
    "node": {
    "slug": "iris",
    "languageCode": "en",
    "databaseId": 3151
    }
    },
    {
    "node": {
    "slug": "alice",
    "languageCode": "en",
    "databaseId": 233
    }
    }
    ]
    },
    "posts": {
    "edges": [
    {
    "node": {
    "id": "cG9zdDo1ODU4NQ==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1ODM4OQ==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1NzgwOA==",
    "languageCode": "en"
    }
    },
    {
    "node": {
    "id": "cG9zdDo1MjYy",
    "languageCode": "en"
    }
    }
    ]
    }
    }
    },
    }

    As you can see it gives same result

    Plugin Author Jason Bahl

    (@jasonbahl)

    @priteshsaxena31 you shared 2 queries and indicated that one is the french query and one is the english query. Neither of them indicate the language.

    Out of the box, WPGraphQL doesn’t work with WPML so you need an extension such as:

    https://github.com/rburgst/wp-graphql-wpml
    or
    https://wpml.org/documentation/related-projects/wpml-graphql/

    Both of these plugins add “language” arguments to the fields in GraphQL so you can query for fields in a specific language.

    For example, the WPML-GraphQL extension on wpml.org shows a query like so:

    {
    posts( where: { language: all } ) {
    nodes { ... }
    }
    }

    In order to get content of a specific language, you will need to specify what language you are asking for content in.

    I would refer to the relevant extension(s) documentation to understand how to accomplish what you’re after.

    Thread Starter priteshsaxena31

    (@priteshsaxena31)

    Hello @jasonbahl Thanks for your response

    For the queries it will be sorted out by id parameter as you can see the id is different in both the queries.

    city(id: “dGVybToxNDM=”) this is English post id

    city(id: “dGVybTo4NjI2”) this is french post id

    Some of the queries is working fine for posts but when i select english or french in this post type i have created a custom post type and a custom taxonomy when i fetch the posts based on taxonomy it gives same result which i have posted here.

    When i check the database the data is correctly saved.

    So what i thought is there is an issue when i fetch data using graphQL. Can you suggest something.

    Plugin Support Joseph Fusco

    (@joefusco)

    Hey @priteshsaxena31, the 2 plugins suggested above might be worth exploring.

    I’m going to mark this as resolved as this has to do with WPML specifically and there are community solutions available. We appreciate your feedback!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.