in_category doesn't work above the loop (4 posts)

  1. jonthejester
    Posted 10 years ago #

    I guess to make things new, putting the following code just below "require('./wp-blog-header.php');" makes in_category() work:
    if ($posts) {
    foreach ($posts as $post) {
    $post_id_list[] = $post->ID;
    $post_id_list = implode(',', $post_id_list);
    $dogs = $wpdb->get_results("SELECT DISTINCT
    ID, category_id, cat_name, category_nicename, category_description, category_parent
    FROM $tablecategories, $tablepost2cat, $tableposts
    WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
    foreach ($dogs as $catt) {
    $category_cache[$catt->ID][] = $catt;
    ...With one slight caveat: the category listing gets repeated. But at least that's something. Could someone help me with the code to make it work like it should? You can check out the progress here: http://daysdifference.com. Thanks.

  2. Beel
    Posted 10 years ago #

    in_category is an "in the loop" function.

  3. jonthejester
    Posted 10 years ago #

    Well... as I found out last night, either in_category() is just for the loop or it's deprecated in favor of is_category() and the whole other bunches of is_'s. But thanks for the reference.
    I guess we can consider this as resolved. Thanks for letting me know that, though.

  4. Beel
    Posted 10 years ago #

    in_category() in loop
    is_category() is not in loop

Topic Closed

This topic has been closed to new replies.

About this Topic