jeudi 29 janvier 2015

Show recent published posts


oI want to list recent published posts of my wp blog and exclude certain posts of some categories. The following code works fine, 10 recent posts are listed and posts in the listed categories are ignored. However, draft posts are listed as well.



$args = array( 'numberposts' => '10', 'tax_query' =>
array(
'post_type' => 'post',
'post_status' => array( 'publish' ),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( 10, 11, 57 ),
'operator' => 'NOT IN',
),
),
)
);



$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '">'. $recent["post_title"].'</a> </li> ';
}
?>


The line with 'post_status' => array( 'publish' ), or 'post_status' => 'publish', does not work. Any clue why?





Aucun commentaire:

Enregistrer un commentaire