• Hi all,

    I’m using this code to get posts by a tag, now I want to use it to get posts by the current page category.

    $recent = new WP_Query(array( 'tag' => 'Reel', 'posts_per_page' => '4', 'offset' => '0' )); while($recent->have_posts()) : $recent->the_post();

    Does anyone have any idea how to get the current category and then what I need to replace tag => reel with?

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter CombatPost

    (@combatpost)

    Fixed with this:

    <?php
    global $post;
    $category = get_the_category($post->ID);
    $category = $category[0]->cat_ID;
    $recent = new WP_Query(array( 'posts_per_page' => '4', 'offset' => 1, 'category__in' => array($category)  )); while($recent->have_posts()) : $recent->the_post();
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Get current category’ is closed to new replies.