Delete a certain category from Wordpress posts

Asked

Viewed 17 times

-1

Friends, I developed a code so that I can display the results of the last posts of a Wordpress site, but I would need only post related to a certain category not appear.

<?php
       // Documentação completa em http://codex.wordpress.org/Class_Reference/WP_Query
        $args = array(
            'orderby' => 'date', //Ordernar por data
            'posts_per_page' => 12, // Número de posts a exibir
        );
        
        $novo_loop = new WP_Query( $args );

        if ( $novo_loop->have_posts() ) : while ( $novo_loop->have_posts() ) : $novo_loop->the_post();  
        ?>
                                <a href="<?php echo get_permalink( $post->ID ); ?>">            
                                    <div class="col">
                                        <div class="brand brand-bottom">
                                           <img src="<?php the_post_thumbnail_url('full'); ?>"  alt="<?php the_title(); ?>" title="Ir para página do <?php the_title(); ?>"/>
                                           <h3 class="item-info-title"><?php echo substr(get_the_title(), 0, 27)?></h3>
                                           <button class="botaodozap">Entrar no grupo</button>
                                        </div>
                                    </div> 
                                </a>
        <?php endwhile; else :?>
            CASO NÃO EXISTA POSTS
        <?php 
            endif;
            // Reseta as queries
            wp_reset_postdata();
        ?>  

how could I implement this? I read something like https://developer.wordpress.org/reference/hooks/block_categories/

2 answers

0

You need to know which is the ID of the category you want to remove. Then add 1 line to your $args.

Suppose you want to remove the category with ID 8:

$args = array(
    'orderby' => 'date', //Ordernar por data
    'posts_per_page' => 12, // Número de posts a exibir
    'cat' => '-8', // Não inclui os posts desta categoria
);

0

You set the category you don’t want to be shown in the Loop within the $args Array

Example:

 'cat' => '-12,-34,-56' 
/*
Exiba todas as postagens, exceto as de uma categoria, 
prefixando seu id com um sinal '-' (menos).
*/

More information on: https://www.billerickson.net/code/wp_query-arguments/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.