web-dev-qa-db-fra.com

Exclure la catégorie de la fonction

QUESTION

Hé les gars, j'ai cette fonction et je dois exclure 2 catégories: 81 et 82. Pouvez-vous aider? :)

CODE

function has_related_same_cat_posts(){
global $post;
$categories = get_the_category($post->ID);

if ($categories) {
    $category_ids = array();
    foreach($categories as $individual_category) 
        $category_ids[] = $individual_category->term_id;

    $args=array(
    'category__in' => $category_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=> 4, // Number of related posts that will be shown.
    'caller_get_posts'=>1,
    'orderby' => 'Rand',

    );

    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
        $return = true;
    } else {
        $return = false;
    }

}

return $return;
}
1
jimilesku
foreach ($categories as $individual_category) {        
    if( $individual_category->term_id == 81 || $individual_category->term_id == 82 ) 
        continue;
    $category_ids[] = $individual_category->term_id; 
}

explication:

ce qui précède remplace:

foreach($categories as $individual_category) 
        $category_ids[] = $individual_category->term_id;

c'est-à-dire que le code saute par-dessus les catégories à exclure.

1
Michael