WordPress.org

Ready to get started?Download WordPress

Forums

wp_get_post_categories() (4 posts)

  1. Southbound
    Member
    Posted 6 years ago #

    $posts = get_posts();
    if ($posts)
    {
    foreach ($posts as $post)
    {
    $post_categories = wp_get_post_categories($post->ID);
    foreach ($post_categories as $cat)
    {

    Now, what is $cat? Codex says wp_get_post_categories() retrieves "the list of categories for a post." So first I thought it was an object, but it's an integer. Could it be the Category ID? No. It's always 1, even if there are posts in different categories. What is it, and how do you use it?

  2. Southbound
    Member
    Posted 6 years ago #

    Sorry for the duplicate posts. I got an error telling me "Topic not found" when posting.

  3. iridiax
    Member
    Posted 6 years ago #

    What are you trying to do? This function returns an array, and the parameter is an integer (post ID). There may be a better choice of function or template tag available. See:

    http://codex.wordpress.org/Template_Tags
    http://codex.wordpress.org/Function_Reference

  4. MichaelH
    Member
    Posted 6 years ago #

    $cat is the variable holding that particular category from the array post_categories. You will want to review http://us3.php.net/foreach

Topic Closed

This topic has been closed to new replies.

About this Topic