WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Get page/post translations (9 posts)

  1. titi5895
    Member
    Posted 1 year ago #

    Hi,

    I would like to store into an array urls of all available translations for a page / post.

    That's possible to do this with a function ? specifying the id_post and id_blog for example

    Thanks in advance.

    http://wordpress.org/extend/plugins/multisite-language-switcher/

  2. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, you can use something like that:

    $temp = array();
    $post = new MslsOptionsPost( $id );
    foreach ( $post->get_arr() as $language => $post_id ) {
        if ( $post->has_value( $language ) )
            $temp[$language] = $post->get_postlink( $language );
    }

    $temp is your array. It works for posts and pages.

    Cheers,
    Dennis.

  3. titi5895
    Member
    Posted 1 year ago #

    Hi Dennis,

    Thanks for your answers.

    I tried you code but nothing happened, $temp stays empty.

    Have you any idea what's wrong?

    Thank you for your help

  4. titi5895
    Member
    Posted 1 year ago #

    [Edit] For posts $temp stays empty but for pages $temp contains the current url (in every lines)

  5. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    Strange. Do you checked that the post with this ID has translations?

  6. titi5895
    Member
    Posted 1 year ago #

    I found the error my function that returns the post id was wrong.

    $temp is no longer empty but for all languages it contains the current url

    [de_DE] => http://de.site.com/post/
    [en_GB] => http://de.site.com/post/
    [es_ES] => http://de.site.com/post/
    [fi] => http://de.site.com/post/
    [fr_FR] => http://de.site.com/post/
    [it_IT] => http://de.site.com/post/
    [pt_PT] => http://de.site.com/post/

  7. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, that's my fault. Try this one:

    $temp  = array();
    $blogs = MslsBlogCollection::instance();
    $post  = new MslsOptionsPost( $id );
    foreach ( $blogs->get_filtered() as $blog ) {
    	if ( $blog->userblog_id != $blogs->get_current_blog_id() ) {
    		$language = $blog->get_language();
    		switch_to_blog( $blog->userblog_id );
    		$temp[$language] = $post->get_permalink( $language );
    		restore_current_blog();
    	}
    }
  8. titi5895
    Member
    Posted 1 year ago #

    This code works very well !

    Thanks a lot Dennis

  9. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    You're welcome!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.