Solved: qTranslate slug with Widget not working with pages

We just saw the issue with qtranslate slug with widget is not working for 0.5 version. URL is showing but URL is not opening and 404 page is opening. we solved  the of qTranslate slug with Widget not working with pages.

Solved issue qTranslate slug with Widget not working with pages

The problem was exactly at the function qTranslateSlug_filter_request inside de file qtranslate-slug-with-widget.php, which is the only one of the plugin, so it’s easy to find.
We must take a look at this part of the code:

if (isset($q['name'])) {
    $type = QTS_POST;
    $slug = $q['name'];
    $param = 'p';
    $get_link = 'get_permalink';
    unset($new_q['name']);
} else if (isset($q['pagename'])) {
    //$type = QTS_PAGE;
    //$slug = $q['pagename'];
    //$param = 'page_id';
    $id = qTranslateSlug_get_page_by_path($q['pagename'], $lang);
    if ($id) {
        unset($new_q['pagename']);
        $q = $new_q;
        $q['page_id'] = $id;
        $get_link = 'get_page_link';
    }
} else if (isset($q['category_name'])) {
    $type = QTS_CAT;
    $slug = $q['category_name'];
    $param = 'cat';
    $get_link = 'get_category_link';
    unset($new_q['category_name']);
} else if (isset($q['tag'])) {
    $type = QTS_TAG;
    $slug = $q['tag'];
    $param = 'tag_id';
    $get_link = 'get_tag_link';
    unset($new_q['tag']);
}

That we hace to replace with the following:

if (isset($q['name'])) {
        $id = qTranslateSlug_get_page_by_path($q['name'], $lang);
        if ($id) {
            unset($new_q['name']);
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        } else {
            $type = QTS_POST;
            $slug = $q['name'];
            $param = 'p';
            $get_link = 'get_permalink';
            unset($new_q['name']);
        }
    } else if (isset($q['pagename'])) {
        $id = qTranslateSlug_get_page_by_path($q['pagename'], $lang);
        if ($id) {
            unset($new_q['pagename']);
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        }
    } else if (isset($q['category_name'])) {
        $type = QTS_CAT;
        $slug = $q['category_name'];
        $param = 'cat';
        $get_link = 'get_category_link';
        unset($new_q['category_name']);
    } else if (isset($q['tag'])) {
        $type = QTS_TAG;
        $slug = $q['tag'];
        $param = 'tag_id';
        $get_link = 'get_tag_link';
        unset($new_q['tag']);
    } else {
        $path = trim(preg_replace('/\?(.*)/', '', $_SERVER['REQUEST_URI']), '/');
        $id = qTranslateSlug_get_page_by_path($path, $lang);
        if ($id) {
            if (isset ($q['attachment'])) {
                unset($q['attachment']);
                unset($new_q['attachment']);
            }
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        }
    }
Solved: qTranslate slug with Widget not working with pages

Solved: qTranslate slug with Widget not working with pages

With the last wordpress versions, mine is 3.3.1, has changed the way of passing the query to the request filter, changing the array slug position from ‘pagename’ to ‘name’, then the plugin didn’t have a way to find any page, since it expected to find in the array the position ‘pagename’, nonexistent for the current case.
Ref is taken from – http://en.codatavern.com/qtranslate-slug-with-widget-wordpress-plugin-fix/

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *