8

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?

10
  • 1
    IMO, it's not fair to ask premium plugin questions here...
    – brasofilo
    Jun 19, 2012 at 3:20
  • "Not fair"? In what way? Why would there be a tag for WPML if it couldn't be asked here? Check the FAQ again, mate. It's licensed under the GPL (even the premium version), so technically I could post any relevant code chunks for others to look at for troubleshooting. That said, at least one of the issues is a core WordPress issue - switch_to_blog() doesn't pass over permalinks for custom post types with get_permalink() - making this a great place to ask about it. Thanks for the downvote, though, it's much more helpful than actually coming up with an answer to a 2 month old question.
    – SickHippie
    Jun 19, 2012 at 3:43
  • Do they have a "free version"? If they do, sorry, I was not aware... If they don't, having a Tag doesn't excuse any GPL...
    – brasofilo
    Jun 19, 2012 at 3:48
  • 2
    Yes, I should have taken it to the Meta before downvoting, now I cannot undo it. Thanks for claryfying, @Bainternet. SickHippie, looks like you haven't got an answer at their forum yet, hope some good soul, while revising old questions, stumbles upon this one and upvote it. Best regards and sorry for the mistake.
    – brasofilo
    Jun 19, 2012 at 10:10
  • 5
    @brasofilo - no worries, mate. I was a bit overstressed yesterday, and apologize for my aggressive attitude. It was uncalled for, and I'm very sorry.
    – SickHippie
    Jun 19, 2012 at 17:26

1 Answer 1

2

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().

Not the answer you're looking for? Browse other questions tagged or ask your own question.