[wp-hackers] how to unassing category from the post?

Rafael Ehlers rafaehlers at gmail.com
Fri Mar 25 16:40:06 UTC 2011


You unset to remove that category entry from the actual list of categories
that your post have and then reassign the new array with that category left
out.

On Fri, Mar 25, 2011 at 1:27 PM, Juan Ulloa
<juan.ulloa at bellevuecollege.edu>wrote:

> OK, I know this is a total n00b question:  Why do you need to unset?
>
> Juan
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com [mailto:
> wp-hackers-bounces at lists.automattic.com] On Behalf Of Konrad Karpieszuk
> Sent: Friday, March 25, 2011 7:03 AM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] how to unassing category from the post?
>
> thank you
>
> full code to use in loop (category is in $cat variable) is:
>
> $kategorie_wpisu = wp_get_post_categories( $post->ID );
>  unset ( $kategorie_wpisu[$cat] );
>  wp_update_post( array('ID' => $post->ID,'post_category' =>
> $kategorie_wpisu));
> unset ( $kategorie_wpisu );
>
> On Fri, Mar 25, 2011 at 2:46 PM, Rafael Ehlers <rafaehlers at gmail.com>
> wrote:
> > I think that you should do something like this:
> >
> > 1. List all categories from a post and assign then to an Array
> > 2. unset the ID from the category you wish to remove
> > 3. wp_update_post( array('ID' => $post->ID,'post_category' =>
> > $arraywithcats));
> >
> > Best regards,
> > Rafael Ehlers
> >
> > On Fri, Mar 25, 2011 at 10:27 AM, Konrad Karpieszuk
> > <kkarpieszuk at gmail.com>wrote:
> >
> >> hello
> >>
> >> suppose that post with ID 4 belongs to category with ID 12, but also
> >> belongs to many other categories.
> >>
> >> is some easy function in wp core to unassign post from particular one
> >> category?
> >>
> >> now in my plugin i am thinking about using wpdb class to update some
> >> term relationship but i am feeling that this is not the best way
> >>
> >> --
> >> (en) regards / (pl) pozdrawiam
> >> Konrad Karpieszuk
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
>
>
>
> --
> (en) regards / (pl) pozdrawiam
> Konrad Karpieszuk
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list