WordPress.org

Ready to get started?Download WordPress

Forums

in_category using array (3 posts)

  1. budster2k1
    Member
    Posted 2 years ago #

    I am trying to check if a title exists within a specific categories I want duplicate titles as long as they are in different categories. I think I need to use in_category with and array as the post_ID comparing if any of the post_ids are in the array. Thanks for any help.

    global $wpdb;
    if ($posts = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_title = '".mysql_real_escape_string($title)."' && post_status = 'publish'", 'ARRAY_A')) {
      if (in_category($cat, $posts) == 1) {
        //Do Nothing
      } else {
        //Do Something
      }
    }
  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

  3. budster2k1
    Member
    Posted 2 years ago #

    print_r ($posts)
    returns
    Array ( [0] => Array ( [ID] => 4071 ) [1] => Array ( [ID] => 7741 ) )
    I am wondering how to use this information to check all the ID's in the array to see if they belong to a category and if any of the ID's are in the specific category skip that post. But when I use $posts the comparison does not find any matching ID's even though there are some. I think it has to do with the two level array but I don't know how to get this to a single array that can be processed in the in_category function. Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic