Php 获取特定类别的所有帖子-Wordpress

Php 获取特定类别的所有帖子-Wordpress,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在尝试获取“Business”类别的所有帖子,并将它们显示在文章模板列表中。但是,查询将返回所有类别的所有帖子 <?php $args = array( 'posts_per_page' => -1, 'post_type' => 'post', 'category-name' => 'Business' ); $the_query = new WP_Query( $arg

我正在尝试获取“Business”类别的所有帖子,并将它们显示在文章模板列表中。但是,查询将返回所有类别的所有帖子

<?php
    $args = array(
        'posts_per_page'   => -1,
        'post_type'        => 'post',
        'category-name'    => 'Business'
    );
    $the_query = new WP_Query( $args );

?>
<?php get_header(  ); ?>
<div class="items-leading">
    <?php while ( $the_query->have_posts() ): $the_query->the_post();?>
<!--Start to display the article-->
<article class="leading-0 item visible-first" id="item-8">
                <!-- Intro image -->
                <figure class="item_img img-intro img-intro__left">
                        <a href="<?php the_permalink(  );?>">
                            <img src="" alt="">
                        </a>
                </figure>

                <!--  title of the article -->
                <header class="item_header">
                <h5 class="item_title heading-style-5 visible-first">
                <a href="<?php the_permalink(  );?>">
                <span class="item_title_part_0 item_title_part_odd item_title_part_first_half item_title_part_first"><?php the_title( );?></span> 
                </a></h5></header>

                <!-- info about the time published and author -->
                <div class="item_info">
                    <dl class="item_info_dl">
                        <dt class="article-info-term"></dt>

                                <dd>
                            <time class="item_published">
                                <?php the_date( );?>    </time>
                        </dd>
                                <dd>
                            <address class="item_createdby">
                            <?php the_modified_author();?>  
                            </address>
                        </dd>
                                <dd>
                            <div class="komento">
                                            </div>
                        </dd>
                            </dl>
                </div>
<!-- Introtext -->
<div class="item_introtext">
    <p>
    <?php echo wp_trim_words( get_the_content(  ), 40, '...')?>
    </p>
</div>

<!-- info BOTTOM -->

<!-- More -->
<a class="btn btn-info" href="<?php the_permalink(  ); ?>">
    <span>
        Read more   
    </span>
</a>
</article>
<div class="clearfix"></div>

<?php endwhile; ?>
</div>
<!-- end items-leading -->
<?php get_footer();?>

Perharps密码有问题吗?但我不明白,因为这个查询是基于我在互联网上找到的。
如果有任何帮助,我将不胜感激

我认为$args有问题,请尝试以下方法:

$args = array(
  'posts_per_page'   => -1,
  'post_type'        => 'post',
  'category_name'    => 'Business'
);

没有任何疑问,只是简单的愚蠢错误

<?php get_header(  ); ?>


将出现在文件的首字母中,然后将您的查询arg&all。

嗯……我不确定,但不知何故,我更改了查询,结果运行良好

太神奇了

<?php get_header(  ); ?>
<?php
    $args = array(
        'posts_per_page'   => -1,
        'post_type'        => 'post',
        'cat'      => '8'
      );
    $the_query = new WP_Query( $args );

?>