Wordpress. Get the tags list newer the specific date and only if the post has specific category

Viewed 31

I need to get list of posts by tag (tag.php) but they have to be filtered: if they are in specific category and the date is before 2020-01-01

1 Answers

If I got you right something like this:

// The query
$the_query = new WP_Query([
    'tag' => 'your-tag',
    'category_name' => 'your-category',
    'date_array' => [
        [
            'before' => 'January 1st, 2020'
        ]
    ]
]);

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
Related