List categories of a custom post

1

I have a Custom post called 'projects'. On certain pages I only need to display projects that have the category 'apps'. So far so good, it displays on a good. However, when I add tags to this project, I can not list just the tags of that particular post. So how can I not list all the categories that the post contains. In the code below it returns all categories, all, including those that are not linked to the post

<?php
      query_posts(
        array(
          'post_type' => 'projects',
          'category_name' => 'apps',
          'showposts' => 3,
          'orderby' => 'date'
          )
        );
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php
       $categories = get_categories($postID);
       var_dump($categories);
?>
    
asked by anonymous 15.07.2016 / 08:19

1 answer

0

You can use wp_get_object_terms() to redeem both tags and < in> categories , since both are taxonomias . In a minimalist way, it is possible to do

<?php

    if(have_posts()){
        while(have_posts()){
            the_post();

            $tags = wp_get_object_terms( $postID , 'post_tag' );

            var_dump($tags);

            $categories = wp_get_object_terms( $postID , 'category' );

            var_dump($categories);
        }
    }

For the sake of curiosity, your use of the get_categories() method is incorrect. It returns a list of category objects (so the error you find), and does not get $postID as argument.

    
17.07.2016 / 22:44