qTranslate: Issues with Duplicate Content?

so i’ve been using this wordpress plugin that will help your site become multilingual called qTranslate. it’s awesome. it allows you to add different translations for menus, posts, pages, widgets, etc with a little bit of effort (of course, every project is different, some php coding may be required). here’s a fairly quick startup guide

the thing is, we only need the plugin for a set of pages and that’s it… not the most ideal solution, but it’s working… or was

i found a random issue that no amount of googling could resolve… every page that didn’t require translation would display fine except for the below snippet of code

essentially, the code was using “get_posts” to display a page within a page (almost inception-like)


$page = get_posts( array(
'name' => [TARGETED_NAME_OF_PAGE],
'post_type' => 'page'
) );

if ( $page )
{
if( $page[0]->post_content != ''){
echo '<div class="module">';
_e( $page[0]->post_content);
echo '</div>';

* note the “_e( $page[0]->post_content);” part

what would happen is if a change was made to that targeted page, the content would display X times, one after the other (where X is the number of languages set)

i noticed that it was calling “_e”, which is similar to using an “echo”

when you do an echo on content, it doesn’t apply any filters or anything and will simply display all the content in the editor

i modified the code like so:


$query = new WP_Query(
array (
'name' => [TARGETED_NAME_OF_PAGE],
'post_type' => 'page'
)
);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<div class="module">';
the_content();
echo '</div>';
}
}
wp_reset_query();

the difference here is the use of “WP_Query” class. with it, i’m able to utilize “the_content()” so the appropriate filters are applied and boom, the proper content is displayed without any duplicates!

Related Posts