• Hi,
    I’am using this plugin to translate the slugs. I have a problem when i want to get the page (post) corresponding to a path, using the wp function “get_page_by_path”.
    I have a url like this https://www.example.com/english-slug/shop and the url https://www.example.com/swede-slug/shop. I have defined a rules that specified the correct page to go when in the url appears the word “shop”.
    When i go to this page i have to get the post corresponding to “english-slug” or “swede-slug”, and this post have to be the same obviously.
    I use the function like this: $post = get_page_by_path(‘english-slug’,OBJECT,’post’); but dont found the page.
    This is a bug in the plugin? Or how can i get the post using the translated slug? without make a query in database of course.
    Thanks!!!

    https://www.ads-software.com/plugins/qtranslate-slug/

Viewing 1 replies (of 1 total)
  • Plugin Author Pedro Carvalho

    (@pedroghandi)

    Hi nicomoka,
    I didn’t quite understood what you are trying to do.

    when are you filtering the url?

    do you have access to the id? if so, you can get the correct url by using:

    $the_slug_in_lang = qts_get_slug( $id, $lang );

    if not, QTS has a private version of get_page_by_path,

    for example, i did this:

    global $qtranslate_slug;
    $this_post = $qtranslate_slug->get_page_by_path(basename( untrailingslashit( qts_get_url() )));
    $this_id = $this_post->ID;
    var_dump($this_id);

    To do that, i had to change the function get_page_by_path signature to public. its in file inc/class-qtranslate-slug.php, line 1225.

    I might create a public function to do that, if there’s a need for that, so you don’t have to keep changing the function.

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with get_page_by_path function’ is closed to new replies.