WordPress – WPML – fix an incorrect language

I had a site using WPML (WordPress Multilingual) where the site’s language picker was set to English but a Chinese translation was consistently showing up for one particular item.

This turned out to be a simple case of the wrong language being set for the post in the database, but to the best of my knowledge you’d never be able to find that out from the UI.

Fortunately it’s easy to detect and fix with some simple PHP and SQL – the examples below use WP-CLI commands.

Firstly, you can use wp shell to verify the language the post is set to.

wpml_get_language_information('',123456);

The language is stored in the wp_icl_translations table, where element_id = the post ID.  So, using wp db query:

update wp_icl_translations set language_code = 'zh-hans' where element_id = 123456;

The above sets the post language to Chinese, which means it won’t be visible when the English version is requested.

Remember to clear any caches you are using.

 

How to install a drupal.org sandbox module using composer

Sandbox modules don’t have a drupal.org/project/foo URL like full contrib modules, and therefore you can’t use composer require drupal/foo to add them.

If you have a Drupal 8 site using drupal-composer/drupal-project, here’s what to edit in composer.json – using a sandbox module of mine as an example.

  1. Within the repositories section
"drupal-wturrell/ckeditor_remove_elementspath": {
    "type": "package",
    "package": {
        "name": "drupal-wturrell/ckeditor_remove_elementspath",
        "version": "0.0.1",
        "type": "drupal-module",
        "source": {
            "url": "https://git.drupal.org/sandbox/wturrell/3018599.git",
            "type": "git",
            "reference": "8.x-1.x"
        }
    }
},

2.  In require (or run composer require with the name you’ve specified)

"drupal-wturrell/ckeditor_remove_elementspath": "^0.0.1",

You can choose any name you like, but drupal-username/module makes sense to me.

Your sandbox module doesn’t need a composer.json file of it’s own.