WordPress.org

Ready to get started?Download WordPress

Forums

Show category ID in posts (3 posts)

  1. roxer82
    Member
    Posted 6 years ago #

    Hello,
    I need show the ID of the category in a post. I used to show it in this way:

    $postid=$post->ID;
    $categoriapost=$wpdb->get_var("SELECT category_id FROM wp_post2cat WHERE post_id=$postid");

    But it doesn't work in the last verion of WP, how can I show it?
    Thanks in advanced!

  2. adeelshahid
    Member
    Posted 6 years ago #

    try to use the post_category field inside the wp_posts table, let me know if it helps.

  3. roxer82
    Member
    Posted 6 years ago #

    Thanks for your answer. I did it using:

    $catpost=$post->post_category;

    But it isn't working, what am I doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags