I want to be able to say array('cat'=>'Current category ID') How do I do this?

So I'm making a wordpress theme and I'm styling archive.php I hope one of you guys can help me with my problem. I'm very new to all of this, so the more thorough the answer is, the better. I'm currently using this:

<?php $the_query = new WP_Query( array('posts_per_page'=>1, 'cat'=>'current_page_category')); ?>

1 answer

  • answered 2019-08-18 07:23 Lazar Momcilovic

    You can get current category ID like this:

    More on this read on WP Codex.

    $current = get_category(get_query_var('cat'));
    $current_id = $current->term_id;
    $args = array(
        'posts_per_page' => 1, 
        'cat' => $current_id,
    $wp_query = new WP_Query($args);