[wp-hackers] how to unassing category from the post?
Konrad Karpieszuk
kkarpieszuk at gmail.com
Fri Mar 25 14:03:13 UTC 2011
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
More information about the wp-hackers
mailing list