Operation: Break the Site II

in the website

List of related articles on the site

It’s going pretty well; I’ve covered most of my initial goals, and now I am taking further steps to pad out content across the site by adding a list of related posts below each article:

$related_posts = new WP_Query(array(
    'post_status' => 'publish',
    'cat' => $category[0]->cat_ID,
    'posts_per_page' => 20,
    'orderby' => 'rand',
    'order' => 'DESC',
    'post__not_in' => array(
    'date_query' => array(
        'inclusive' => false,
        'after' => get_the_date('Y-m-j') . ' -180 days',
        'before' => get_the_date('Y-m-j') . ' -7 days',

Pick ten posts from the same category, in a range between 7 and 180 before the date of the post, and output three random ones.


in me

Your email address will not be published. Required fields are marked *