我想在Wordpress中排除某些帖子?

时间:2018-10-30 18:47:50

标签: php wordpress post wordpress-theming

大家好,我遇到一个问题,在wordpress中,我使用post__not_in来不显示id 10的类别。我尝试了此操作,但它似乎仍然适用于该帖子。您是否有解决此问题的方法。谢谢大家!

<?php
                 $cat_args = array(
             'orderby' => 'post_date',
             'order' => 'DESC',
             'child_of' => 0,
             'post__not_in' => array(10),
                 );

            $categories =   get_categories($cat_args);


            foreach($categories as $category) {
                 echo '<dl>';
                 echo '<h3 class="category-name">' . $category->name.'</h3>';

                    $post_args = array(
                     'numberposts' => -1,
                     'category' => $category->term_id
                 );

                 $posts = get_posts($post_args);

                 foreach($posts as $post) {
                 ?>
                         <dd><a class="article" target="_blank" href="<?php the_field('article_link') ?>"><?php the_title(); ?></a><span class="news-source"> - <?php the_field('news_source') ?></span><p class="important"><?php the_field('important') ?></p></dd>
                 <?php
                 }
                 //echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>View all posts in ' . $category->name.'</a></dd>';
                 echo '</dl>';
                 }

                 ?>

1 个答案:

答案 0 :(得分:0)

这对我来说似乎很有效:'exclude' => array(10)