Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

We encountered an issue querying custom post types by a slug with graphql, and it works only for the posts in the site's default language, e.i. If the site's default language is English, this query for the post will work:

query getArticlesByslug {
  article(id: "the-latest-eng-article", idType: SLUG) {
    title
    content
  }
}

But if we change the site's default language to say Belarusian, the query will return null.

Solution:

1. Add this function to the functions.php file of your theme.

add_filter('request', function($vars){
    if (isset($vars['graphql']) && !empty($vars['name'])) {
        $vars['suppress_filters'] = true;
    }
 
    return $vars;
});

2. Save the file and reload the homepage of your site.

The issue has been escalated to our developers, and they will try to improve this in future versions of WPML GraphQL

Relevant Documentation:

https://wpml.org/documentation/related-projects/wpml-graphql/

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.

Our next available supporter will start replying to tickets in about 6.64 hours from now. Thank you for your understanding.

Tagged: ,

This topic contains 6 replies, has 2 voices.

Last updated by Itamar 1 year, 1 month ago.

Assisted by: Itamar.

Author Posts
August 5, 2023 at 5:06 pm #14158997

ivanD-50

Hello, we encountered an issue querying custom post types by a slug with graphql, it works only for the posts in the sites default language, e.i. if the sites default language is english this query for the post will work:

query getArticlesByslug {
  article(id: "the-latest-eng-article", idType: SLUG) {
    title
    content
  }
}

but if we change the sites default language to say belarusian, the query will return null. I'll attach the full query log

{
  "data": {
    "article": null
  },
  "extensions": {
    "debug": [],
    "tracing": {
      "version": 1,
      "startTime": 1691255095.582305,
      "endTime": 1691255095.630679,
      "duration": 48373,
      "execution": {
        "resolvers": [
          {
            "path": [
              "article"
            ],
            "parentType": "RootQuery",
            "fieldName": "article",
            "returnType": "Article",
            "startOffset": 39673,
            "duration": 7219
          }
        ]
      }
    },
    "queryLog": {
      "queryCount": 25,
      "totalTime": 0.008626699447631836,
      "queries": [
        {
          "sql": "SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'",
          "time": 0.0014719963073730469,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), wp_not_installed, is_blog_installed, wp_load_alloptions"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = '_wpml_inactive' LIMIT 1",
          "time": 0.00017189979553222656,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'active_sitewide_plugins' LIMIT 1",
          "time": 0.00012493133544921875,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), load_essential_globals, get_site_option, get_network_option, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = '_icl_cache' LIMIT 1",
          "time": 0.0004711151123046875,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), WPML\\Container\\make, call_user_func_array, WPML\\FP\\{closure}, call_user_func_array, WPML\\Container\\{closure}, WPML\\Container\\Container::make, WPML\\Auryn\\Injector->make, WPML\\Auryn\\Injector->provisionInstance, WPML\\Auryn\\Injector->instantiateWithoutCtorParams, SitePress->__construct, WPML_Flags_Factory->create, icl_cache->__construct, icl_cache->init, icl_cache_get, get_option"
        },
        {
          "sql": "\t\n\t\t\t\tSELECT option_value\n\t\t\t\tFROM wp_options\n\t\t\t\tWHERE option_name = 'home'\n\t\t\t\tLIMIT 1\n\t\t\t",
          "time": 0.00014591217041015625,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), WPML\\Container\\make, call_user_func_array, WPML\\FP\\{closure}, call_user_func_array, WPML\\Container\\{closure}, WPML\\Container\\Container::make, WPML\\Auryn\\Injector->make, WPML\\Auryn\\Injector->provisionInstance, WPML\\Auryn\\Injector->instantiateWithoutCtorParams, SitePress->__construct, SitePress->set_term_filters_and_hooks, wpml_is_rest_request, WPML_REST_Request_Analyze->is_rest_request, WPML_REST_Request_Analyze->get_uri_part, wpml_strip_subdir_from_url, WPML_URL_Converter->get_abs_home, WPML_URL_Converter_Url_Helper->get_abs_home, WPML_URL_Converter_Url_Helper->get_unfiltered_home_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'wpml_tf_settings' LIMIT 1",
          "time": 0.0002391338348388672,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), WPML_TF_Settings_Read->get, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'wp_installer_settings' LIMIT 1",
          "time": 0.0004470348358154297,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/sitepress-multilingual-cms/sitepress.php'), activate_installer, WP_Installer_Setup, OTGS\\Installer\\Settings::load, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'WPLANG' LIMIT 1",
          "time": 0.0002200603485107422,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/advanced-custom-fields-pro/acf.php'), acf, ACF->initialize, __, translate, get_translations_for_domain, _load_textdomain_just_in_time, determine_locale, get_locale, get_option"
        },
        {
          "sql": "\n\t\t\t\tSELECT\n\t\t\t\t\tl.code,\n\t\t\t\t\tm.locale,\n\t\t\t\t\tl.default_locale\n\t\t\t\tFROM wp_icl_languages AS l\n\t\t\t\tLEFT JOIN wp_icl_locale_map AS m ON m.code = l.code\n\t\t\t",
          "time": 0.00024390220642089844,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/advanced-custom-fields-pro/acf.php'), acf, ACF->initialize, __, translate, get_translations_for_domain, _load_textdomain_just_in_time, determine_locale, get_locale, apply_filters('locale'), WP_Hook->apply_filters, SitePress->locale_filter, WPML_Locale->locale, WPML_Locale->get_locale, WPML_Locale->get_all_locales"
        },
        {
          "sql": "SELECT * FROM wp_users WHERE user_login = 'admin' LIMIT 1",
          "time": 0.00026297569274902344,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, SitePress->maybe_set_this_lang, WPML_Request->set_language_cookie, WPML\\Language\\Detection\\CookieLanguage->set, is_user_logged_in, wp_get_current_user, _wp_get_current_user, apply_filters('determine_current_user'), WP_Hook->apply_filters, wp_validate_logged_in_cookie, wp_validate_auth_cookie, get_user_by, WP_User::get_data_by"
        },
        {
          "sql": "SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN (1) ORDER BY umeta_id ASC",
          "time": 0.0005400180816650391,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, SitePress->maybe_set_this_lang, WPML_Request->set_language_cookie, WPML\\Language\\Detection\\CookieLanguage->set, is_user_logged_in, wp_get_current_user, _wp_get_current_user, apply_filters('determine_current_user'), WP_Hook->apply_filters, wp_validate_logged_in_cookie, wp_validate_auth_cookie, get_user_by, WP_User->init, WP_User->for_site, WP_User->get_caps_data, get_user_meta, get_metadata, get_metadata_raw, update_meta_cache"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = '_wpml_media' LIMIT 1",
          "time": 0.000186920166015625,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, do_action('wpml_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, WPML_Media->loaded, WPML_Media::init_settings, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'wpml_word_count_requested_types_status' LIMIT 1",
          "time": 0.00019097328186035156,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, do_action('wpml_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wpml_tm_load, WPML_Action_Filter_Loader->load, WPML_Action_Filter_Loader->load_factory_or_action, WPML_Action_Filter_Loader->load_factory, WPML_Action_Filter_Loader->run_factory, WPML_TM_Word_Count_Hooks_Factory->create, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'wpml_notices' LIMIT 1",
          "time": 0.0002300739288330078,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, do_action('wpml_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wpml_tm_load, WPML_Action_Filter_Loader->load, WPML_Action_Filter_Loader->load_factory_or_action, WPML_Action_Filter_Loader->load_factory, WPML_Action_Filter_Loader->run_factory, WPML_TM_Upgrade_Loader_Factory->create, wpml_get_admin_notices, WPML_Notices->__construct, WPML_Notices->get_all_notices, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = '_wpml_dismissed_notices' LIMIT 1",
          "time": 0.00011181831359863281,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->init, do_action('wpml_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wpml_tm_load, WPML_Action_Filter_Loader->load, WPML_Action_Filter_Loader->load_factory_or_action, WPML_Action_Filter_Loader->load_factory, WPML_Action_Filter_Loader->run_factory, WPML_TM_Upgrade_Loader_Factory->create, wpml_get_admin_notices, WPML_Notices->__construct, WPML_Notices->get_all_dismissed, get_option"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'can_compress_scripts' LIMIT 1",
          "time": 0.0002620220184326172,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, wp_widgets_init, do_action('widgets_init'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Widget_Factory->_register_widgets, WP_Widget->_register, WP_Widget_Text->_register_one, wp_add_inline_script, wp_scripts, WP_Scripts->__construct, WP_Scripts->init, do_action_ref_array('wp_default_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, wp_default_packages, wp_register_tinymce_scripts, script_concat_settings, get_site_option, get_network_option, get_option"
        },
        {
          "sql": "\n\t\t\tSELECT   wp_posts.*\n\t\t\tFROM wp_posts \n\t\t\tWHERE 1=1  AND wp_posts.post_type = 'acf-taxonomy' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled'))\n\t\t\t\n\t\t\tORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC\n\t\t\t\n\t\t",
          "time": 0.0002930164337158203,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF->init, do_action('acf/init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF_Taxonomy->register_taxonomies, ACF_Internal_Post_Type->get_posts, ACF_Internal_Post_Type->get_raw_posts, get_posts, WP_Query->query, WP_Query->get_posts"
        },
        {
          "sql": "SELECT option_value FROM wp_options WHERE option_name = 'sticky_posts_be-by' LIMIT 1",
          "time": 0.00012993812561035156,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF->init, do_action('acf/init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF_Taxonomy->register_taxonomies, ACF_Internal_Post_Type->get_posts, ACF_Internal_Post_Type->get_raw_posts, get_posts, WP_Query->query, WP_Query->get_posts, get_option, apply_filters('pre_option_sticky_posts'), WP_Hook->apply_filters, WPML_Sticky_Posts_Sync->pre_option_sticky_posts_filter, get_option"
        },
        {
          "sql": "\n\t\t\tSELECT   wp_posts.*\n\t\t\tFROM wp_posts \n\t\t\tWHERE 1=1  AND wp_posts.post_type = 'acf-post-type' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled'))\n\t\t\t\n\t\t\tORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC\n\t\t\t\n\t\t",
          "time": 0.00016999244689941406,
          "stack": "require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF->init, do_action('acf/init'), WP_Hook->do_action, WP_Hook->apply_filters, ACF_Post_Type->register_post_types, ACF_Internal_Post_Type->get_posts, ACF_Internal_Post_Type->get_raw_posts, get_posts, WP_Query->query, WP_Query->get_posts"
        },
        {
          "sql": "\n\t\t\tSELECT   wp_posts.*\n\t\t\tFROM wp_posts \n\t\t\tWHERE 1=1  AND wp_posts.post_type = 'acf-field-group' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled'))\n\t\t\t\n\t\t\tORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC, wp_posts.ID DESC \n\t\t\t\n\t\t",
          "time": 0.0004019737243652344,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->__construct, WPGraphQL::get_schema, WPGraphQL\\Registry\\SchemaRegistry->get_schema, WPGraphQL\\Registry\\TypeRegistry->init, do_action('init_graphql_type_registry'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Registry\\TypeRegistry->init_type_registry, do_action('graphql_register_types'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\ACF\\Config->init, WPGraphQL\\ACF\\Config->get_location_rules, acf_get_field_groups, acf_get_internal_post_type_posts, ACF_Internal_Post_Type->get_posts, ACF_Internal_Post_Type->get_raw_posts, get_posts, WP_Query->query, WP_Query->get_posts"
        },
        {
          "sql": "\n\t\tSELECT ID, post_name, post_parent, post_type\n\t\tFROM wp_posts\n\t\tWHERE post_name IN ('the-latest-eng-article')\n\t\tAND post_type IN ('page','attachment')\n\t",
          "time": 0.00029587745666503906,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WPGraphQL\\Data\\NodeResolver->parse_request, get_page_by_path"
        },
        {
          "sql": "\n\t\t\t\t\t\t\t\t\t\t SELECT post_type, post_name\n\t\t\t\t\t\t\t\t\t\t FROM wp_posts p\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN wp_icl_translations wpml_translations\n\t\t\t\t\t\t\t\t\t\t\tON wpml_translations.element_id = p.ID\n\t\t\t\t\t\t\t\t\t\t\t    AND CONCAT('post_', p.post_type) = wpml_translations.element_type\n\t\t\t\t\t\t\t\t\t\t        AND p.post_type  IN ('post','page','attachment','wp_block','wp_template','wp_template_part','wp_navigation','articles','longreads' ) \n\t\t\t\t\t\t\t\t\t\t WHERE post_name = 'the-latest-eng-article'  AND post_type IN ('articles')\n\t\t\t\t\t\t\t\t\t\t    AND ( post_status = 'publish'\n\t\t\t\t\t\t\t\t\t\t        OR ( post_type = 'attachment'\n\t\t\t\t\t\t\t\t\t\t             AND post_status = 'inherit' ) )\n\t\t\t\t\t\t\t\t\t\t    ORDER BY post_type = 'page' ASC, CASE wpml_translations.language_code WHEN 'be-by' THEN 4  WHEN 'en' THEN 2  WHEN 'ru' THEN 1  ELSE 0 END DESC  ,  CASE p.post_type  WHEN 'page' THEN 2  WHEN 'post' THEN 1  ELSE 0 END DESC \n\t\t\t\t\t\t\t\t\t     LIMIT 1",
          "time": 0.0004680156707763672,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, WP_Query->parse_query, do_action_ref_array('parse_query'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->parse_query, WPML_Query_Parser->parse_query, WPML_Query_Parser->maybe_adjust_name_var, WPML_404_Guess->guess_cpt_by_name, WPML_404_Guess->find_post_type"
        },
        {
          "sql": "\n\t\t\t\tSELECT ID\n\t\t\t\t FROM wp_posts p\n\t             JOIN wp_icl_translations wpml_translations\n\t\t\t\t\tON p.ID = wpml_translations.element_id\n\t\t\t\t\t\tAND wpml_translations.element_type = CONCAT('post_', p.post_type )  WHERE p.post_type = 'articles' AND  p.post_name = 'the-latest-eng-article'\n\t\t\t\tORDER BY p.post_parent = 0 DESC\n\t\t\t\t",
          "time": 0.0007290840148925781,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, WP_Query->parse_query, do_action_ref_array('parse_query'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->parse_query, WPML_Query_Parser->parse_query, WPML_Query_Parser->maybe_adjust_name_var, WPML_Name_Query_Filter->filter_page_name, WPML_Name_Query_Filter->query_needs_adjustment, WPML_Name_Query_Filter->get_single_slug_adjusted_IDs, WPML_Name_Query_Filter->get_single_slug_adjusted_IDs_from_DB"
        },
        {
          "sql": "SELECT wpml_translations.translation_id, wpml_translations.element_id, wpml_translations.language_code, wpml_translations.source_language_code, wpml_translations.trid, wpml_translations.element_type\n\t\t\t\t    FROM wp_icl_translations wpml_translations\n\t\t\t\tJOIN wp_posts p\n\t\t\t\t\tON wpml_translations.element_id = p.ID\n\t\t\t\t\t\tAND wpml_translations.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t    JOIN wp_icl_translations tridt\n\t\t\t\t      ON tridt.element_type = wpml_translations.element_type\n\t\t\t\t      AND tridt.trid = wpml_translations.trid\n\t\t\t\t    WHERE  tridt.trid = (SELECT trid FROM wp_icl_translations wpml_translations\n\t\t\t\tJOIN wp_posts p\n\t\t\t\t\tON wpml_translations.element_id = p.ID\n\t\t\t\t\t\tAND wpml_translations.element_type = CONCAT('post_', p.post_type) WHERE element_id = 88 LIMIT 1)",
          "time": 0.00042891502380371094,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, WP_Query->parse_query, do_action_ref_array('parse_query'), WP_Hook->do_action, WP_Hook->apply_filters, SitePress->parse_query, WPML_Query_Parser->parse_query, WPML_Query_Parser->maybe_adjust_name_var, WPML_Name_Query_Filter->filter_page_name, WPML_Name_Query_Filter_Translated->select_best_match, WPML_Name_Query_Filter_Translated->get_matching_page_in_requested_lang, WPML_Element_Translation->get_element_lang_code, WPML_Element_Translation->maybe_populate_cache"
        },
        {
          "sql": "\n\t\t\tSELECT   wp_posts.*\n\t\t\tFROM wp_posts  JOIN wp_icl_translations wpml_translations\n\t\t\t\t\t\t\tON wp_posts.ID = wpml_translations.element_id\n\t\t\t\t\t\t\t\tAND wpml_translations.element_type = CONCAT('post_', wp_posts.post_type) \n\t\t\tWHERE 1=1  AND wp_posts.post_name = 'the-latest-eng-article' AND wp_posts.post_type = 'articles' AND ( ( ( wpml_translations.language_code = 'be-by' OR 0 ) AND wp_posts.post_type  IN ('post','page','attachment','wp_block','wp_template','wp_template_part','wp_navigation','articles','longreads' )  ) OR wp_posts.post_type  NOT  IN ('post','page','attachment','wp_block','wp_template','wp_template_part','wp_navigation','articles','longreads' )  )\n\t\t\t\n\t\t\tORDER BY wp_posts.post_date DESC, wp_posts.ID DESC \n\t\t\t\n\t\t",
          "time": 0.00038909912109375,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WP_Query->__construct, WP_Query->query, WP_Query->get_posts"
        }
      ]
    },
    "queryAnalyzer": {
      "keys": "d2af86025c9bbdf6211d67e8aa21ade4c7b82e0c7b6f9cc564c7239824f62423 graphql:Query operation:getArticlesByslug list:article",
      "keysLength": 119,
      "keysCount": 4,
      "skippedKeys": "",
      "skippedKeysSize": 0,
      "skippedKeysCount": 0,
      "skippedTypes": []
    }
  }
}
August 7, 2023 at 9:51 am #14162641

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Please check our guide here.

https://wpml.org/documentation/related-projects/wpml-graphql/

You need to use the "language" attribute. For example like this.

query PostsES{
  posts(where: {language: "es"}) {
    nodes {
      slug
      uri
    }
  }
}

Regards,
Itamar.

August 7, 2023 at 10:36 am #14162951

ivanD-50

Hi, the query in your reply is for the list of posts, but we have a problem querying a single post by its slug

query getArticlesByslug {
  article(id: "the-latest-eng-article", idType: SLUG) {
    title
    content
  }
}

this type of query doesn't support the "language" attribute, and we should be able to query the post by its slug, because each translation of the post has its own unique slug.

August 7, 2023 at 10:52 am #14163063

ivanD-50

And i should probably add how the custom post type is registered

function create_custom_posttype()
{

    register_post_type('articles',
        array(
            'labels' => array(
                'name' => 'Articles',
                'singular_name' => 'Article'
            ),
            'supports' => array('title', 'editor', 'thumbnail', 'author'),
            'public' => true,
            'has_archive' => false,
            'show_in_graphql' => true,
            'graphql_single_name' => 'article',
            'graphql_plural_name' => 'articles',
            'hierarchical' => false,
        )
    );
}

add_action('init', 'create_custom_posttype');
August 7, 2023 at 2:40 pm #14164643

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, and thanks for the additional information.

I'm consulting our second-tier supporters about this case and will update you once I receive their reply.

I appreciate your patience.

August 9, 2023 at 7:40 am #14173171

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Our second-tier supporter asked me to escalate this issue so the second-tier supporters' team can investigate it and if needed, escalate it to our developers. I'll keep you updated on nay news here.

August 9, 2023 at 2:18 pm #14176675

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Our second-tier supporter suggests the following workaround.

1. Add this function to the functions.php file of your theme.

/**
 * @see wpmlsupp-10969
 */
add_filter('request', function($vars){
	if (isset($vars['graphql']) && !empty($vars['name'])) {
		$vars['suppress_filters'] = true;
	}

	return $vars;
});

2. Save the file and reload the homepage of your site.

Our second-tier supporter explains that WPML is not automatically adjusting the post type slug and looking for the post in the primary language. That does not exist. With the above code, we will turn off WPML filters if it is a GraphQL request and has a post slug in its request.

Please let me know if this works for you.

August 10, 2023 at 8:43 am #14180397

ivanD-50

Hi, with this filter the query seems to work as expected, thanks a lot for the support

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.