Was using database queries to retrieve Post Titles in some of my template files, but unfortunately it was returning the title in ALL languages including the QTranslate tags…
<!--:en-->Aberdeen<!--:--><!--:de-->Aberdeen<!--:--><!--:zh-->Aberdeen<!--:-->
So I made a function with regex to find the post title of the correct language and then remove the excess tags, placed in my functions.php file:
<?php
// Function to get correct QTranslate post title
function getTransText($text) {
// regex using correct language
$lang=qtrans_getLanguage();
preg_match('/<!--:'.$lang.'-->(.*?)<!--:-->/', $text, $matches);
// Returns correct version of Post Title
return strip_tags($matches[0]);
}
?>
Then I could just get the correct language title using
<?php echo getTransText($text); ?>
Let me know if you have a better/smarter/smaller way of doing the same thing!
That’s already implemented in qTranslate. Use __() to get the correct title or _e() to echo it.
This has helped me again and again when customizing themes!
Thank youuuuuuuuuuuuuuuuuuu!!!!