Search code examples
phpwordpresswpml

WPML wordpress: how to check if page doesn't exist in a language?


I wrote this function

function get_wpml_page($id){
    $pageID = apply_filters( 'wpml_object_id', $id , 'page', true );
    return $pageID;
}

It works great, you give it an id in english, it will return the translated version of this id, my only problem is that if it doesn't find the language, it reverts back to english.

I need a function just like that one, which returns false or null if it doesn't find a translation. So that I would be able to give it an id, translate it if a translation exist, and remove it if it doesn't.


Solution

  • All I had to do is change the last argument to false

    function is_wpml_page($id){
        $pageID = apply_filters( 'wpml_object_id', $id , 'page', false );
        return $pageID;
    }