• I have a WordPress multisite, in a page I load posts from other blogs with the function “switch_to_blog()”
    But the post content (title, content, qtranslate acf field…) is not returned correctly.
    Example: blog with ‘it’ language get posts from blog with “ar” and “en” languages.
    I have a loop foreach post ID, on this loop I tried this:
    $title = get_post($id)->post_title; //Here I get back the full string [:ar]…[:en]///[:]
    and this
    $title = get_the_title($id); // Here I get back an empty string.

    However, for another blog (“it” blog get posts from blog with “cn” and “en” languages), I have the same title for both “en” and “cn” languages so the 2 codes above return the title correctly.

    Is there a way when querying for a post field, to force one language and avoid the horrible string with qtranslate tags ? I didn’t find anything to achieve this. My only correct option here is to get the full string and use PHP regex to cut the string as I want.

    Plugins used :
    ACF Qtranslate : 1.7.22
    QtranslateX: 3.4.6.8

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter valentinjcqmt

    (@valentinjcqmt)

    After some research I found that the problem is that on the subsite with Italian language, I got empty string for translated fields (title and qtranslate acf text field). I think the problem come from the fact that the plugin search for Italian translation, but there is no Italian translation on the other subsites (English, Chinese and Arabic only).

    So for the title, on the WPPost Object there is a variable “post_title_ml” containing the qtranslate full string of the title ([:cn]Title – cn[:en]Title – en[:]), and I achieved to get the English version with regex and string manipulaiton.
    But for the acf qtranslate text field, I can’t do it teh same way, I only have empty string with the function “get_field()”.

    What can I do about it ?

    @valentinjcqmt – First of all qTranslate is a best and number 1 rank plugin for multilingual. As I understood and little assume that You have multisite network setup website and if you set multisite as “each language for each blog”(one-To-one) OR “all language for each/single blog”(many-To-one)
    You have to use function “switch_to_blog” and after loop end use function “restore_current_blog”. Suppose(many- To-one) you want to get posts from italian language/blog then you have to write the code as like:

    switch_to_blog(itlainian-lang-blog-id);
    // function qtrans_use($lang, $text, $show_available=false) Read more about this function
    $post_id=47;// assume post id
    $post = get_page($post_id); 
    $title= qtrans_use('it', $post->post_content,false); // it - language
    echo $content;
    restore_current_blog();
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Compatibility with “swicth_to_blog” function’ is closed to new replies.