0
I am taking care of a news site in Wordpress and I realized that when it is selected more than one category by matter of the following conflict:
By the URL I am on the page of the category Lifestyle only that it returns the matter of Health/ Beauty. These matters are marked as category :Lifestyle, Health/Beauty. This is the code of the categories page
get_header(); ?>
    <div id="primary" class="content-area">
        <main id="main" class="site-main">
        <div class="container">
            <div class="row">
<?php
        if ( have_posts() ) : ?>
            <header class="page-header">
<?php
$args = array(
    'category_name' => $slug
);
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
    $term = array_pop($terms);
    $cor = get_field('cor', $term );
    $slug = $term->slug;
endif;
?>
<h1 style="color:<?php echo $cor; ?>" class="page-title tac"><?php echo $term->name; ?></h1>
            </header><!-- .page-header -->
<!-- Notícia em destaque -->            
<!-- Notícia sozinha na DIV -->
            <?php
                                    $terms = get_the_terms( get_the_ID(), 'category');
                                    if( !empty($terms) ) :
                                        $term = array_pop($terms);
                                        $slug = $term->slug;
                                    endif;
                            // The Query
                            $args = array(
                                'post_type' => 'post',
                                'posts_per_page' => 2,
                                'category_name' => $slug
                            );
                            $query = new WP_Query( $args );
                            if ( $query->have_posts() ) :
                                $cols = 0;
                                $ids = array();
                                while ( $query->have_posts() ) : $query->the_post();
                                $ids[] = get_the_ID();
                                $terms = get_the_terms( get_the_ID(), 'category');
                                    if( !empty($terms) ) :
                                        $term = array_pop($terms);
                                        $cor = get_field('cor', $term );
                                    endif;
                                    ?>
<div class="col-md-6">
    <a href="<?php echo get_permalink(); ?>">
        <h1 class="title-main" style="color:<?php echo $cor; ?>">
            <?php echo get_field('titulo_chamada'); ?>
        </h1>
    </a>
    <a href="<?php echo get_permalink(); ?>">
        <div class="img-destaque img-responsive" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
            <div class="tag-category branco" style="background-color: <?php echo $cor; ?>">
                <?php echo $term->name; ?>
            </div>  
        </div>
    </a>
     <?php the_excerpt(); ?>
</div>
                                    <?php
                                endwhile;
                                /* Restore original Post Data */
                                wp_reset_postdata();
                endif;
            ?>
                        <!-- PUBLICIDADE -->
                        <div class="col-md-6 col-xs-12 img-responsive mw100pc" style="float: right;">
                            <?php echo do_shortcode("[pro_ad_display_adzone id=1043]"); ?>
                        </div>
<!-- Quatro primeiras notícias -->
<div class="col-md-12">
     <div class="row">
        <?php
            $terms = get_the_terms( get_the_ID(), 'category');
                            if( !empty($terms) ) :
                                $term = array_pop($terms);
                                $slug = $term->slug;
                            endif;
                            // The Query
                            $args = array(
                                'post_type' => 'post',
                                'post__not_in' => $ids,
                                'posts_per_page' => 4,
                                'category_name' => $slug,
                                ‘showposts’ => 1, 
                                ‘paged’=>$paged
                            );
                            $query = new WP_Query( $args );
                            if ( $query->have_posts() ) :
                                $cols = 0;
                                while ( $query->have_posts() ) : $query->the_post();
                                $ids[] = get_the_ID();
                                $terms = get_the_terms( get_the_ID(), 'category');
                                    if( !empty($terms) ) :
                                        $term = array_pop($terms);
                                        $cor = get_field('cor', $term );
                                    endif;
                                    ?>
            <div class="col-md-3" style="height: 620px;">
                <a href="<?php echo get_permalink(); ?>">
                    <h1 class="title-main" style="color:<?php echo $cor; ?>">
                        <?php echo get_field('titulo_chamada'); ?>
                    </h1>
                </a>
                <a href="<?php echo get_permalink(); ?>">
                    <div class="img-destaque" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
                        <div class="tag-category branco" style="background-color: <?php echo $cor; ?>">
                            <?php echo $term->name; ?>
                        </div>  
                    </div>
                </a>
                <?php the_excerpt(); ?>             
            </div>
            <?php                   
                endwhile;       
                    /* Restore original Post Data */
                    wp_reset_postdata();
                endif;
            ?>
     </div>
</div>
<!-- Resto das noticias da categoria -->
        <div class="col-md-12">
            <div class="slide-noticias">
            <?php
            $terms = get_the_terms( get_the_ID(), 'category');
                                    if( !empty($terms) ) :
                                        $term = array_pop($terms);
                                        $slug = $term->slug;
                                    endif;
                            // The Query
                            $args = array(
                                'post_type' => 'post',
                                'post__not_in' => $ids,
                                'posts_per_page' => 4,
                                'category_name' => $slug,
                                ‘showposts’ => 1, 
                                ‘paged’=>$paged
                            );
                            $query = new WP_Query( $args );
                            if ( $query->have_posts() ) :
                                $cols = 0;
                                while ( $query->have_posts() ) : $query->the_post();
                                $ids[] = get_the_ID();
                                $terms = get_the_terms( get_the_ID(), 'category');
                                    if( !empty($terms) ) :
                                        $term = array_pop($terms);
                                        $cor = get_field('cor', $term );
                                    endif;
                                    ?>
                                    <div class="col-md-3" style="height: 620px;"><a href="<?php echo get_permalink(); ?>">
                                    <h1 class="title-main" style="color:<?php echo $cor; ?>"><?php echo get_field('titulo_chamada'); ?></h1></a>
                                        <a href="<?php echo get_permalink(); ?>">
                                        <div class="img-destaque" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
                                        <div class="tag-category branco" style="background-color: <?php echo $cor; ?>"><?php echo $term->name; ?></div> 
                                        </div>
                                        </a>
                                        <?php the_excerpt(); ?>             
                                    </div>
                                    <?php
                                endwhile;
                                /* Restore original Post Data */
                                wp_reset_postdata();
                endif;
            ?> 
            </div>
        </div>
            <!-- Paginação -->
            <div class="clear"></div>
            <br />
            <br />          
            <!--BANNER-->
                 <div class="col-xs-12 img-responsive" id="closer">
                    <?php echo do_shortcode("[pro_ad_display_adzone id='1049' class='banner-categoria']"); ?>
             <a hrfe="#" class="modal-close hidden-xs" onclick="document.getElementById('closer').style.display='none'"></a>
                </div>  <!-- /.publicidade -->
                        <div class="clear"></div>
<!-- PROVISÓRIO -->
<hr>
                        <?php
                                // The Query
                                $args = array(
                                    'post_type' => 'post',
                                    'category_name' => $term->slug,
                                    'post__not_in' => $ids,
                                    'posts_per_page' => 10
                                );
                                $query = new WP_Query( $args );
                                if ( $query->have_posts() ) :
                                    $colun = 1;
                                        while ( $query->have_posts() ) : $query->the_post();
                                        $terms = get_the_terms( get_the_ID(), 'category');
                                        if( !empty($terms) ) :
                                            $term = array_pop($terms);
                                            $cor = get_field('cor', $term );
                                        endif;
                                        ?>
                                            <?php if($colun == 1 or $colun == 6) : ?><div class="col-md-6"><?php endif; ?>
                                            <a href="<?php echo get_permalink(); ?>" style="color:<?php echo $cor; ?>"><h1 class="title-resume"><?php echo get_field('titulo_chamada'); ?></h1></a>
                                            <?php echo get_the_date(); ?>
                                            <hr>
                                            <?php if($colun == 5 or $colun == 10) : ?></div><?php endif; ?>
                                        <?php
                                        $colun++;
                                    endwhile;
                                    /* Restore original Post Data */
                                    wp_reset_postdata();
                                endif;
                            ?>
<?php endif; ?> <!-- DEVE PERMANECER NA PÁGINA -->
        </main><!-- #main -->
    </div><!-- #primary -->
    <br />
    <br />
    <br />
<?php
get_footer();
?>
<script type="text/javascript" async src="https://d335luupugsy2.cloudfront.net/js/loader-scripts/7270b716-ffb6-4f76-8de0-9f09b12a4159-loader.js"></script>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-68151385-5', 'auto');
  ga('send', 'pageview');
</script>
<script>
$('.slide-noticias').slick({
  infinite: true,
  slidesToShow: 4,
  slidesToScroll: 4,
  dots: true,
  infinite: false,
  speed: 300,
  slidesToShow: 4,
  slidesToScroll: 4,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 3,
        infinite: true,
        dots: true
      }
    },
    {
      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 2
      }
    },
    {
      breakpoint: 480,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }
    // You can unslick at a given breakpoint now by adding:
    // settings: "unslick"
    // instead of a settings object
  ]
});
</script>
His solution worked in parts, he began to return the matters but he brought all the matters related to Lifestyle. For example: in Fashion he is bringing Health/Beauty, Lifestyle, in Health/Beauty he brings Fashion, Lifestyle and I want him to bring only the chosen category. And on the gastronomy page persists the same before. :/
– Luiz Furlan
In Fashion he is bringing posts that nay has the fashion category?
– Ricardo Moraleida
I just saw that I had overwritten the $Terms variable in my example. I switched to $term_ids there, see if anything changes.
– Ricardo Moraleida
I switched the variable and it didn’t change anything. Regarding the first question, is returning all posts (lifestyle, fashion, health/beauty) and it was to return only fashion or just health/beauty, depending on the page that the guy selected. See: http://piradigital.com.br/categoria/moda
– Luiz Furlan
The first post (Column Ergolife:) that this marked as health and beauty, tb is as lifestyle (by URL). It does not have the fashion category?
– Ricardo Moraleida
Not the only trendy posts are: "Four nineties trends that have come back with everything!" and "Dress Code Fashion Italy brings fashion and behavior tips"
– Luiz Furlan
Do you have any idea what it might be?
– Luiz Furlan