• 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
      }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter budster2k1

    (@budster2k1)

    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

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘in_category using array’ is closed to new replies.