Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So here's my code, using the qTranslate plugin:

    query_posts(array('post_type' => 'uk_blog', 'numberposts' => 2));
    $i = 0; while(have_posts()): the_post($post);?>
    <div class="third-column"<?php if ($i == 1) echo ' style="margin-right:0;"';?>>
        <h2><a href="<?php get_permalink($post->ID);?>"><?php the_title();?></a></h2>
        <div class="inner">
            <?php $length = strlen(get_the_content());
            echo nl2br(substr(strip_tags(get_the_content()), 0, 500));
            if ($length > 500){
                echo '...<br /><a href="' . get_permalink($post->ID) . '">Read more</a>';
            }
            ?>
        </div>
    </div>
    <?php $i++; endwhile;?>

The post titles (using the_title();) are actually appearing in all languages at the same time, ie: English titleFrench titleSpanish title.

Viewing the HTML source shows that the qTranslate tags that define which bit of a string is for which language are being directly outputted. IE the HTML source is

<!--:en-->English title<!--:--><!--:fr-->French title<!--:-->

The posts are from a custom post type.

Any ideas why this might be?

Thanks for reading!

share|improve this question
    
Does the link take you to the correct language page? –  Daniel Sachs Sep 17 '12 at 9:41
add comment

3 Answers

I've experienced issues like this with qTranslate, and the first thing you should do definitely is to make sure that you are using the_title() or the the_title filter, as suggested by Daniel Sachs.

Since your widget is already calling the_title() that's clearly not the case. On a few occasions (specifically while updating WordPress or qTranslate) I have had to edit the posts in order for them to display correctly. Try to edit the affected post, switch between the tabs and try deleting and reinserting the titles into the respective fields. Weirdly enough, that has solved problems like this for me.

share|improve this answer
add comment

Hi Will also try this:

Add this to your functions.php

function get_qTrans_TitleText($text) {
  $language=qtrans_getLanguage();
  preg_match('/<!--:'.$language.'-->(.*?)<!--:-->/', $text, $matches);
  return strip_tags($matches[0]);
}

And then:

<?php echo get_qTrans_TitleText($text); ?>

Have no Idea what version of qTranslate and WP you have so you may even use __() to get the correct title or _e() to echo it.

share|improve this answer
    
Isn't __() and _e() etc. just for accessing strings in the gettext database? All qTranslate does is using regex to pull the correct portion of the post_title/post_content fields, right? –  Simon Sep 20 '12 at 17:26
add comment

Try using

<h2>
    <a href="<?php get_permalink($post->ID);?>">
        <?php echo apply_filters('the_title', $post->post_title); ?>
    </a>
</h2>
share|improve this answer
    
I'm afraid it doesn't work - the same thing happened. Forgot to mention that I'm using a custom post type, will edit my question to include that –  Will Sep 17 '12 at 10:29
    
You know what? After you updated the post, I wonder if query_posts has something to do with it... Try using WP_Query instead to see if it has any effect –  Daniel Sachs Sep 17 '12 at 12:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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