I’ve got something about this on the WPML support forums, but I figured I could ask here as well. Here’s the important info: I’m running a WP Multisite setup with custom post types, custom fields, custom everything it seems. In a particular template file, I’ve got a secondary loop that’s pulling a list of items from a different blog. From what I gathered, anything using the WP API should be filtered down to only the current language, but none of the WP_Query() functions I’ve got are doing so.

Relevant code:

<?php 
 switch_to_blog(23);
$args = array('post_type' => 'release-notes',
    'suppress_filters' => 0,
    'meta_query' => array(
            array(
                'key' => 'related_products',
                'value' => $thisproduct,
                'compare' => 'LIKE'
            )
        )
    );
$loop = new WP_Query($args);
if ($loop->have_posts()) {
    echo '<h2>Release Notes</h2>';
    while ( $loop->have_posts() ) : $loop->the_post();
        //echo '<pre>';
        //print_r($post);
        //echo '</pre>';
        $post_link = ($post->post_name);
        echo '<p><a class="text-link" href="' . get_permalink() . '">' . get_the_title() . '</a></p>';
    endwhile; // foreach($posts
} // if ($results
restore_current_blog();
?>

The problem here is twofold: first, it’s returning results from every language instead of the current language – the same post, three times (EN, FR, DE). Second, the result from get_permalink() is completely wrong – it’s spitting out http://www.mysite.com/blog23name/postname instead of http://www.mysite.com/blog23name/lang/posttype/postname – the custom permalink shown on the ‘edit post’ page.

Any ideas?

1
1

My solution was to register the custom post types on the site where I’m calling it from, then in WPML’s settings set them to translate. This is in WPML -> Translation Management -> Multilingual Content Setup, down at the bottom. I assume it works by tricking WP into using that site’s rewrite/translate rules when it doesn’t have the proper info from switch_to_blog().

Leave a Reply

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