WordPress.org

Ready to get started?Download WordPress

Forums

wpdb->post2cat doesn't exists anymore (2 posts)

  1. Luigino
    Member
    Posted 4 years ago #

    Hello everyone!!!

    I'm here asking you a little thing.

    I have this code using WPDB class:

    $result = $wpdb->get_results('select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, '.$wpdb->posts.' as posts where postmeta.post_id = posts.ID AND posts.post_status = "publish" AND postmeta.meta_key = "expiration-date"');

    and I'd like to have also the category ID of the post_id, and since wpdb->post2cat doesn't exists anymore from version 2.5, which JOIN should add to have it?

    And is there maybe a function or something already in the WPDB class which would allow me to "move" the post from category to another? sort of like an update...

    Thanks in advance to everyone!
    Ciao
    Luigi

  2. MichaelH
    Member
    Posted 4 years ago #

    $result = $wpdb->get_results('select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, '.$wpdb->posts.' as posts where postmeta.post_id = posts.ID AND posts.post_status = "publish" AND postmeta.meta_key = "expiration-date"');

    That should still work okay as nothing has really changed with the postmeta table.

    The post2cat table was replaced by the terms tables. Look at Displaying_Posts_Using_a_Custom_Select_Query for some examples.

    Also see Function_Reference/wp_set_post_categories

Topic Closed

This topic has been closed to new replies.

About this Topic