Support » Fixing WordPress » I am trying to retrieve my categories translated with Polylang to display articl

  • frenchywp

    (@frenchywp)


    I am translating a carousel that allows to display different cooking items according to the language and according to the current category, it worked well (when I’m on a dessert item, my carousel displays first a dessert, then a dish etc .. the problem is that I changed the translations of certain categories and my script that allows translation (with polylang) doesn’t detect my change and displays an article from another category to the instead, I wonder what would be my mistake in this code (this is the code that determines the display of cooking items according to the nature of the recipe, the default language is french):

    $recipeTypes = array('entree', 'plat-principal', 'dessert');
    
        $currentType = get_field('recipe_type');
    
        if (!empty($currentType)){
            $currentType = get_term($currentType[0]);
    
            if (!empty($currentType)){
                if (substr($currentType->slug, 0, 14) == 'plat-principal'){
                    $recipeTypes = array('antipasti', 'entree', 'dessert');
                }
                elseif (substr($currentType->slug, 0, 7) == 'dessert') {
                    $recipeTypes = array('antipasti', 'entree', 'plat-principal');
                }
                elseif (substr($currentType->slug, 0, 9) == 'antipasti') {
                    $recipeTypes = array('entree', 'plat-principal', 'dessert');
                }
                elseif (substr($currentType->slug, 0, 7) == 'entree') {
                    $recipeTypes = array('antipasti', 'plat-principal', 'dessert');
                }
            }
        }
        ?>

    and here is the rest of the code:

    <?php
    
        $currenttPostId = get_the_ID();
        $theCategory = get_the_terms(get_the_ID(),'recipe_category');
    
        $prevNext = array();
    
        if (!empty($search_args)) {
    
            $search_args['posts_per_page'] = -1;
    
        foreach($recipeTypes as $recipeType){
    
            $recipeType = get_term_by('slug',  $recipeType.'-'.pll_current_language(), 'recipe_type');
    
            $args = array(
                'post_type'         => 'recipe',
                'posts_per_page'    => 1,
                'orderby'           => 'rand',
                'meta_key'          => 'recipe_type',
                'meta_value'        => $recipeType->term_id,
                'meta_compare'      => 'LIKE'
            );
    
            $results = new WP_Query($args);
    
            array_push($recipes, array($results->posts[0], '', $recipeType->name));
    
            }
        }   
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘I am trying to retrieve my categories translated with Polylang to display articl’ is closed to new replies.