0

i am going to filter my loop base on the category the problem is that when i am using the following code it display all my post.

// Query args
$custom_cat_args = array(
    'posts_per_page' => 15,
    'order' => 'DESC',
    'orderby' => 'post_date',
    'category' => get_cat_ID( 'سیاست' )
);
// Instantiate query
$custom_cat_query = new WP_Query( $custom_cat_args );
// Instantiate loop
if ( $custom_cat_query->have_posts() ) : while ( $custom_cat_query->have_posts() ) : $custom_cat_query->the_post();
    // Normal loop markup here
// Close loop
endwhile; endif;
// Restore $post global
wp_reset_postdata();
1

There's no valid query argument - category, it could be category_name or cat. So for your query, you can use -

$custom_cat_args = array(
    'posts_per_page' => 15,
    'order' => 'DESC',
    'orderby' => 'post_date',
    'cat' => get_cat_ID( 'سیاست' )
);

Or

$custom_cat_args = array(
    'posts_per_page' => 15,
    'order' => 'DESC',
    'orderby' => 'post_date',
    'category_name' => 'سیاست'
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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