Skip to content

Instantly share code, notes, and snippets.

@j0lvera
Created December 8, 2014 22:38
Show Gist options
  • Save j0lvera/d5aa7d2db9ca8481cd3b to your computer and use it in GitHub Desktop.
Save j0lvera/d5aa7d2db9ca8481cd3b to your computer and use it in GitHub Desktop.
How to print categories in a post, WordPress
<?php
$categories = get_the_category( $post-> ID );
$category = $categories[0]->cat_name;
// How to use it
$args = array(
'post_type' => 'post-type-name',
'category_name' => $category
);
$query = new WP_Query( $args );
while ( $query->have_posts() ): $query->the_post;
the_permalink();
endwhile;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment