作者排除的Wordpress短代码

作者排除的Wordpress短代码,wordpress,author,Wordpress,Author,我在WordPress中有一个短代码,显示了作者的最后一篇文章,问题是我想排除一个具体的作者(ID=13)。快捷码是下一个: function latest_posts_c( $array ) { global $post; $defaults = array( 'show' => 3, 'excerpt' => 'false', 'post_type' => 'post', ); ext

我在WordPress中有一个短代码,显示了作者的最后一篇文章,问题是我想排除一个具体的作者(ID=13)。快捷码是下一个:

function latest_posts_c( $array ) {
    global $post;

    $defaults = array(
         'show' => 3,
         'excerpt' => 'false',
         'post_type' => 'post',
    );

    extract( shortcode_atts( $defaults, $array ) );

    $args = array(
        'posts_per_page' => $show,
        'post_type' => $post_type,
    );

    // Gets posts form database
    $query = new WP_Query( $args );

    // Displays posts if available
    if( $query ) {
        $i = 0;

        while ( $query->have_posts()) : $query->the_post();
            if ($i == 0)
                $html = '<div class="column dt-sc-one-third first">';
            else
                $html .= '<div class="column dt-sc-one-third">';

            $html .= '<article id="post-'.get_the_ID().'" class="'.implode(' ', get_post_class('blog-entry')).'">';
            $html .= '<div class="blog-entry-inner">';

            $html .= '<div class="entry-meta">';
            $html .= '  <a href="'.get_permalink().'" title="'.get_the_title().'" class="entry_format"> </a>';
            $html .= '  <div class="date">';
            $html .= '      <p>'.get_the_date('M').' '.get_the_date('d').' <span>'. get_the_date('Y') .'</span> </p>';
            $html .= '  </div>';
            $html .= '</div><!-- .entry-meta -->';

            if( has_post_thumbnail() ):
                $html .= '<div class="entry-thumb">';
                $html .= '  <a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail(get_the_ID(), 'medium').'</a>';
                $html .= '</div><!-- .entry-thumb -->';
            endif;

            $html .= '<div class="entry-details">';
            if(is_sticky()):
            $html .= '  <div class="featured-post"> <span class="fa fa-trophy"> </span> Destacado</div>';
            endif;

            $html .= '  <div class="entry-title">';
            $html .= '      <h4><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h4>';
            $html .= '  </div>';

            $html .= '  <div class="entry-metadata">';
            $html .= '      <p class="author">';
            $html .=    '<span class="fa fa-user"> </span>';
            $html .= '          <a href="'.get_author_posts_url(get_the_author_meta('ID')).'" title="Ver todos las entradas de '.get_the_author().'">'.get_the_author().'</a></p>'; 
            $categories = 0;/*get_the_category();*/
            $separator = ', ';
            $output = '';
            if($categories){
                $j = 0;
                foreach($categories as $category) {
                    $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "Ver todos las entradas en %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>';
                    $j++;
                    if ($j < count($categories)) $output .= $separator;
                }       
                $html .= '      <p class="categories"><span class="fa fa-folder-open"> </span>'.$output.'</p>';
            }
            $html .= '  </div><!-- .entry-metadata-->';

            $html .= '  <div class="entry-body">';
            $html .= '      '.dttheme_excerpt(50);
            $html .= '      <p><a href="'.get_permalink().'" title="'.get_the_title().'" class="dt-sc-button small read-more">';
            $html .= '      Leer más <span class="fa fa-angle-double-right"> </span></a></p>';
            $html .= '  </div>';

            $html .= '</div><!-- .entry-details -->';

            $html .= '</div><!-- .blog-entry-inner-->';
            $html .= '</article>';
        $html .= '</div>';

        $i++;
        endwhile;
    }

    $html .= '<div class="dt-sc-clear"></div>';

    // Resets Post Data
    wp_reset_postdata();

    // Returns the results
   return $html;
}
add_shortcode('latestposts_c', 'latest_posts_c');
函数最新发布($array){
全球$员额;
$defaults=数组(
“显示”=>3,
'摘录'=>'假',
“post_type”=>“post”,
);
提取(shortcode_atts($defaults,$array));
$args=数组(
“每页帖子”=>$show,
“post\u type”=>$post\u type,
);
//获取表单数据库中的帖子
$query=新的WP\u查询($args);
//显示文章(如果可用)
如果($query){
$i=0;
而($query->have_posts()):$query->the_post();
如果($i==0)
$html='';
其他的
$html.='';
$html.='';
$html.='';
$html.=''.获取日期('M')。'.获取日期('d')。'.获取日期('Y')。

'; $html.=''; $html.=''; 如果(已发布缩略图()): $html.=''; $html.=''; $html.=''; endif; $html.=''; 如果(是粘性的()): $html.='Destacado'; endif; $html.=''; $html.=''; $html.=''; $html.=''; $html.='

'; $html.=''; $html.='

'; $categories=0;/*获取_类别()*/ $separator=','; $output=''; 如果($类别){ $j=0; foreach($categories作为$category){ $output.=''; $j++; 如果($j'; } $html.=''; $html.=''; $html.=''.dttheme_摘录(50); $html.='

'; $html.=''; $html.=''; $html.=''; $html.=''; $html.=''; $i++; 结束时; } $html.=''; //重置Post数据 wp_reset_postdata(); //返回结果 返回$html; } 添加快捷码(“最新帖子”、“最新帖子”);
我添加了一个If来阻止代码,如果有来自author ID=13的帖子,但问题是短代码没有显示任何内容。我还使用了“authors\u in”来允许数组$args和$default中的某些authors ID,但什么都没有……有什么想法吗?

试试这个:

$args = array(
    'posts_per_page' => $show,
    'post_type' => $post_type,
    'author'   => '-13'
);
author参数可以设置为包括/排除特定作者

参考文献