How can I filter by slug depending on language selection

I’m new to this site but looking at the quality of answers provided here I will be here for a long time 🙂

Ok, first a bit of info:

Read More

I’m developing a bilingual website (English & Japanese) using WordPress and the WPML Multi-lingual CMS.
The site is for a cafe in Tokyo, Japan. All the products names and descriptions have been written in English and translated into Japanese. Doing so, using WPML, produces 2 identical products, 1 in English and 1 in Japanese. The slugs are named after the product name, so for example the product “Caramel Cappuccino” has the slug “caramel-cappuccino”. And, the corresponding Japanese version has the slug “caramel-cappuccino-ja”. This is the same for all products in both languages with all the Japanese version products getting -ja at the end.

Now comes my problem:

There is a template, that was included by the author of the theme, that produces a Menu like you would see in a restaurant.
The problem is that the menu displays all of the products in both languages regardless of whether English or Japanese has been selected as the language of the site by the user.
So, if you check the links below, you will see that all the products are displayed twice.
You can see the current situation here:

English: http://www.oasis-radio.net/mobile/wordpress/menu/
Japanese: http://www.oasis-radio.net/mobile/wordpress/ja/menu-ja/

What I want to do:

I want to create some kind of loop, where if the the language selection is English, only the English versions of the products are displayed and likewise, if the language selection is Japanese, only the Japanese versions of the products are displayed.
I’ve tried a few different things but can’t seem to get anything to work.

This is the php code for the template that produces the Menu page:

    <?php
/**
 *
 * A custom page template without sidebar, full width.
 *
 * @package WordPress
 * @subpackage Ermark Adora
 *
 */

    get_header();

    echo '<div class="section clearfix">';
        if (get_option('ermad_products_menu_of_the_day', 'false')=='true') {
            echo '<div class="menuDescription">';       
        }

             if ( have_posts() ) while ( have_posts() ) : the_post(); 
                 if ( is_front_page() ) { 
                    echo '<h2 class="entry-title">'.get_the_title().'</h2>';
                 } else { 
                    echo '<h1 class="entry-title">'.get_the_title().'</h1>';
                 } 

                the_content();

                wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'adora' ), 'after' => '</div>' ) );

                edit_post_link( __( 'Edit', 'adora' ), '<span class="edit-link">', '</span>' );
            endwhile;


        if (get_option('ermad_products_menu_of_the_day', 'false')=='true') {
            echo '</div>';
            echo '<div class="menuDayOffer">';
                echo '<p>'.get_option('ermad_products_menu_description', 'Go to admin panel to edit this description, you must add text for two lines for shure.').'</p>';
                loadProductsInOffer();
            echo '</div>';
        }

    echo '</div>';

    ?>  
        <div class="section hr"></div>

        <div class="section clearfix">

            <div id="wrapper-prices-center" >
            <div id="wrapper-prices-bottom" >
            <div id="wrapper-prices-top" >

            <?php  loadProductsCateg(); ?>

            </div>          
            </div>          
            </div>          
        </div>          

        <div class="section hr"></div>

<?php 

get_footer(); ?>

Any help would be greatly appreciated!

Dan

Related posts

Leave a Reply

1 comment

  1. WPML has a feature called “Automatically Adjust IDs” which detect when specific items are loaded and adjust IDs so that the results are adjusted for the active language.

    This functionality is enabled by default and can be accessed via WPML->Languages (visible in Advanced mode):