[wp-hackers] Custom Post Types and Taxonomy
Charles Frees-Melvin
wordpress at cefm.ca
Mon Nov 1 22:16:09 UTC 2010
So basically, something along the lines of a parameter to register_taxonomy of support_default_term have false to disable and a string to define the default term. Then strip out the code that creates the default category and then put support_default_term as Uncategorized. But then add logic so that it will recognize if it was changed.
On 2010-11-01, at 7:05 PM, Nicolas Kuttler wrote:
> On Thu, Oct 28, 2010 at 05:30:57PM +0100, Ana Aires wrote:
>> Hi everyone,
>>
>> I have defined a new custom post type and assigned a new taxonomy, to it. I
>> would like to define as default 2 terms of this taxonomy when a new post is
>> created. Any ideas on how I can accomplish this?
>
> I do something similar in my pastebin plugin. I save the default term as
> a plugin option and basically do something like
>
> add_action( 'wp_insert_post', 'update_post_terms' );
>
> function update_post_terms( $post_id ) {
> if ( $parent = wp_is_post_revision( $post_id ) )
> $post_id = $parent;
> $post = get_post( $post_id );
> if ( $post->post_type != 'post' )
> return;
>
> // add a tag
> wp_set_post_terms( $post_id, 'new tag', 'post_tag', true );
>
> // add a category
> $categories = wp_get_post_categories( $post_id );
> $newcat = get_term_by( 'name', 'Some Category', 'category' );
> array_push( $categories, $newcat->term_id );
> wp_set_post_categories( $post_id, $categories );
> }
>
> http://www.nkuttler.de/paste/1hn/
>
>
> --
> Nicolas Kuttler
> wp at nkuttler.de
>
> http://www.nkuttler.de
> http://www.nicolaskuttler.de (deutsch)
> _______________________________________________
> 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