0

I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.

Here is my code:

<?php do_action( 'hitmag_before_content' ); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
       <h1>Latest News</h1>
        <?php do_action( 'hitmag_before_blog_posts' ); ?>
              <?php $args = array(
                        'post_type' => 'post' ,
                        'orderby' => 'date' ,
                        'order' => 'DESC' ,
                        'posts_per_page' => 3,
                        'category'         => '30','33','1',
                        'paged' => get_query_var('paged'),
                        'post_parent' => $parent
                   ); ?>
                   <?php query_posts($args); ?>
        <?php

            if ( have_posts() ) :

                if ( is_home() && ! is_front_page() ) : ?>
                    <header>
                        <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
                    </header>

                <?php
                endif;

                $archive_content_layout = get_option( 'archive_content_layout', 'th-grid-2' );
                echo '<div class="posts-wrap ' . esc_attr( $archive_content_layout ) . '">';

                    /* Start the Loop */
                    while ( have_posts() ) : the_post();

                        /*
                        * Include the Post-Format-specific template for the content.
                        * If you want to override this in a child theme, then include a file
                        * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                        */
                        get_template_part( 'template-parts/content', get_post_format() );

                    endwhile;

                echo '</div><!-- .posts-wrap -->';

                

            else :

                get_template_part( 'template-parts/content', 'none' );

            endif; ?>

        <?php do_action( 'hitmag_after_blog_posts' ); ?>

    </main><!-- #main -->
</div><!-- #primary -->

2 Answers 2

0

The short answer is that the value for category should be an array of IDs.

The longer answer is that it is rarely appropriate to use query_posts at all.

1
  • Hello, thanks for the reply. How can I show headline before displaying the posts from each category?
    – Imtango30
    Commented Aug 13, 2020 at 14:57
0

Use category__in instead of category.

So just replace:

'category'         => '30','33','1',

with

'category__in'         => array( '30','33','1'),
1
  • Hello, thanks for the reply. How can I show headline before displaying the posts from each categories?
    – Imtango30
    Commented Aug 13, 2020 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.