WordPress.org

Ready to get started?Download WordPress

Forums

Getting the post category in functions.php? (3 posts)

  1. wrybread
    Member
    Posted 1 year ago #

    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?

  2. David Gard
    Member
    Posted 1 year ago #

    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.

  3. David Gard
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.