I'm trying to exclude articles if are older than 2 years, related articles by category, but it just doesn't work.
<?php $args = array('date_query' => array('post_date_gmt', 'before' => '24 month ago' ),
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID),
'orderby'=>'rand', 'numberposts' => 4, 'post__not_in' => array($post->ID) )));
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<a class='' href='<?php the_permalink(); ?>' >
<?php the_title(); ?>
</a><br>
<?php } wp_reset_postdata(); ?>
rand
as it's very very slow and expensive. Can you format your code? It's very difficult to read.