wordpress loop for specific category

Pretty sure query_posts is the worst way to query…

Always use get_posts from what I’m constantly told.
Remove the arguments that you don’t use on the array below.

$args  = array(
    'posts_per_page'  => 5000,
    'offset'          => 0,
    'category'        => ,
    'orderby'         => 'post_date',
    'order'           => 'ASC',
    'include'         => ,
    'exclude'         => ,
    'meta_key'        => ,
    'meta_value'      => ,
    'post_type'       => 'post',
    'post_mime_type'  => ,
    'post_parent'     => ,
    'post_status'     => 'publish',
    'suppress_filters' => true ); 
$posts = get_posts($args);
    foreach ($posts as $post) :
    ?><div class="">
        <a href="https://wordpress.stackexchange.com/questions/85609/<?php the_permalink();?>">
          <?php 
               echo the_title();
               echo the_post_thumbnail(array(360,360));
               the_excerpt('more text');
          ?></a></div>
    <?php endforeach; ?>
<?php 

WP_query method with category id’s:

$query = new WP_Query( array( 'category__in' => array( 2, 6 ), 'order' => 'ASC') );

Or change the query like this, but I don’t know how to add ascending to it:

    add_action( 'pre_get_posts', 'add_my_custom_post_type' );

    function add_my_custom_post_type( $query ) {
        if ( $query->is_main_query() )
            $query->set( 'category', 'A' );
         // $query->set( 'order', 'ASC' ); maybe?
        return $query;
    }

Leave a Comment