• hi.,

    i am using a magzine theme and wp-o-matic to fetch rss and converting it into posts.,
    some posts comes with no-poster.jpg image and falls under category named “premium category”

    my homepage displays posts from “premium category”

    but some of them has blank images like /path/no-poster.jpg

    so i want to find such posts in the premium category and remove that post from “premium category”

    coz as i have installed post corrector, single posts comes under various categories.

    i dont want delete post, i just want to remove such posts from “premium category”

    thanks.

Viewing 1 replies (of 1 total)
  • I’m trying to figure out how to do this as well. What I really want is a function that accepts a post ID and a category ID and removes the association between that post and that category. That function doesn’t seem to exist.

    The best way I have thought of to do this is first to use wp_get_object_terms to get an array of the category IDs the post is assigned to, then find the specific category ID I’m looking for and remove it from the array, then use wp_set_object_terms, passing it the post ID again, the revised array of category IDs, and the $append parameter set to FALSE so that it assigns only those categories to the post and removes all others. This strikes me as a very klunky way to do something that seems like it ought to be simple. Here’s my code (untested):

    $term=get_term_by(‘name’,’Name of Category to Remove’,’category’);
    $categories=wp_get_object_terms($post->ID,’category’);
    $index = array_search($term,$categories);
    unset($categories[$index]);
    wp_set_object_terms($post->ID, $categories,’category’,false);

    Surely there is a better way?

Viewing 1 replies (of 1 total)
  • The topic ‘remove post from specific category using conditional tag ?’ is closed to new replies.