I'm trying to display 'related articles', I do this now like this:
<?php
$exclude = get_the_ID();
$args = array(
'post_type' => 'article',
'posts_per_page' => 3,
);
$your_query = new WP_Query( $args );
echo '<ul>';
while( $your_query->have_posts() ) : $your_query->the_post();
if( $exclude != get_the_ID() ) {
echo '<li><a href="' . get_permalink() . '">' .
get_the_title() . '</a></li>';
}
endwhile;
echo '</ul>';
?>
This works great.. But the custom post type 'articles' actually also has categories. So I'd like to only display links from within the same category.
This is where I'm stuck, I tried giving my args array a new line:
$category = get_the_category();
$args = array(
'post_type' => 'article',
'posts_per_page' => 3,
'cat'=> $category
);
But this doesn't do the trick.
Any suggestions?