WordPress.org

Support

Support » How-To and Troubleshooting » Getting the post category in functions.php?

Getting the post category in functions.php?

  • wrybread

    @wrybread

    I have a custom function to make an excerpt for our posts, and in that function I can get the post title like this:

    $post_title = get_the_title();

    And the text of the post with this:

    $text = get_the_content(”);

    But for various reasons I need to get the category of the post, and I don’t see how to do that.

    Any advice for that?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try get_the_category($id);Function Reference.

    If that is no good, maybe wp_get_object_terms($object_ids, $taxonomies, $args); (although this would return an array of Terms as objects, so you’d need to work them to get the display that you wanted – Function Reference.

    Also, not sure of exactly what you are doing, but maybe get_the_excerpt(); would be good for you? This does have to be in The Loop though, so maybe that is why you have chosed to ignore it – Function Reference.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting the post category in functions.php?’ is closed to new replies.