WordPress.org

Ready to get started?Download WordPress

Forums

Show post_category (2 posts)

  1. roxer82
    Member
    Posted 6 years ago #

    Hello, I need to show the category ID in my posts. Here I found how to do it: http://codex.wordpress.org/Function_Reference/get_post#Usage
    I was trying to do soiomething like this but it shows "0":
    $category = $post->post_category ;
    As I am using WordPress 2.2 I must do it using the $post2cat table.
    Here I found something about it: http://codex.wordpress.org/Database_Description20
    But I don't know how to do it, how can I do it?
    Thanks in advanced!

  2. triffid
    Member
    Posted 6 years ago #

    Its probably too late to help you, but for anyone else trying to do this the following select works. An array of objects is returned from which you need the 'category_id' property.

    $wpdb->get_results("SELECT * FROM $wpdb->post2cat WHERE post_ID = $post->ID ORDER BY category_ID");

Topic Closed

This topic has been closed to new replies.

About this Topic