Created
August 3, 2010 21:38
-
-
Save anonymous/507200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Custom post type relation test | |
* @version 0.1 | |
*/ | |
/* | |
Plugin Name: Custom post type relation test | |
Plugin URI: http://wordpress.org/# | |
Description: Custom post type relation test | |
Author: Laurent Dinclaux <lox.dev@knc.nc> | |
Version: 0.1 | |
Author URI: http://www.knc.nc | |
*/ | |
/* registers post type */ | |
$args = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); | |
$args->label = 'Movie'; | |
$args->public = true; | |
$args->supports = explode(',', 'title,editor,excerpt,page-attributes'); | |
register_post_type( 'movie', (array)$args ); | |
$args->label = 'Actor'; | |
register_post_type( 'actor', (array)$args ); | |
/* registers taxonomy */ | |
$args = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); | |
$args->label = 'Actors'; | |
register_taxonomy('actors',array('movie', 'actor'), (array)$args ); | |
function cptr_transition_post_status ($new_status, $old_status, $post) { | |
if($post->post_type === 'actor') { | |
// status changes | |
if($new_status !== $old_status) { | |
if($new_status === 'publish') { | |
wp_set_object_terms($post->ID, $post->post_name, 'actors'); | |
} | |
else { | |
if($term = get_term_by( 'name', $post->post_name, 'actors' ) ) { | |
wp_delete_term($term->term_id, 'actors'); | |
} | |
} | |
} | |
// no status change and status is publish | |
if( $new_status === $old_status && $new_status === 'publish') { | |
// updates the taxonomy name if needed | |
} | |
} | |
} | |
add_action('transition_post_status', 'cptr_transition_post_status', 10,3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment