WordPress.org

Ready to get started?Download WordPress

Forums

check if array of post ids are in_category (2 posts)

  1. budster2k1
    Member
    Posted 2 years ago #

    i am checking if a post title exists already with

    if ($posts = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_title = '".mysql_real_escape_string($ap_cron_title)."' && post_status = 'publish'", 'ARRAY_A')) {

    which returns an array now I need to check that array to see if any of those posts exist in a category. If any of the post are in the category it does nothing but if it doesn't exist in the category a post is added.

    I add posts from multiple vendors and they sometimes have the same titles for products so I check to see if that product name already exists then check to see if it is in the current vendors category. If it is not the post gets added to that category. I've tried a foreach for each post_ID and check if they are in_category but what happens with this is if the title is used by two or more vendors and i run the check for in_category and one show that it is not in category and the other is in category but in the foreach it adds the post for the on that doesnt match the category creating duplicate entrys so I need to somehow check the array of all post_ID's that are generated after the title check against the category of the new post.

  2. Chouby
    Member
    Posted 2 years ago #

    Maybe the function wp_get_post_terms (or wp_get_object_terms) can help you. You can use it to return all the categories your post belongs to.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.