taxonomy - Wordpress Taxonomies -
i'm ready cry!
i've done lot of google searches can't quite piece of coding working way want to.
in wordpress have following taxonomy:
active - open - in-progress - awaiting parts - pending / on-hold - awaiting pick-up closed https://dl.dropboxusercontent.com/u/30177707/wo-tax.png
what child displayed specific post , if there no children display parent.
heres screenshot i've edited gives better picture of i'm asking. https://dl.dropboxusercontent.com/u/30177707/stackoverflow.png
this code i've been playing with:
$terms = wp_get_post_terms($post->id, 'pctracker_workorderstatus'); $count = count($terms); if ( $count > 0 ){ foreach ( $terms $term ) { echo $term->name .'<br>'; } } at present displaying parent , child post.
would grateful or direction!
thanks, jase
you'll have edit column content :
this example code adapt needs, @ terms ones parents , childs. depending of results display parents or childs. in case, there 1 parent and/or 1 child. code should work. (not tested)
function mycustomposttype_custom_columns( $column_name, $id ) { switch ( $column_name ) { case 'status': $terms = wp_get_post_terms($id, 'pctracker_workorderstatus'); $count = count($terms); if ( $count > 0 ) { $parents = array(); $childs = array(); foreach ( $terms $term ) { if(!empty($term->parent)) { $childs[] = $term; } else { $parents[] = $term; } } //display parent if there no child if(empty($childs)) { foreach($parents $p) { echo $p->name; } } elseif(!empty($parents) && !empty($childs)) { //don't display parent foreach($childs $p) { echo $p->name; } } } break; default: break; } // end switch } add_action( 'manage_mycustomposttype_posts_custom_column', 'mycustomposttype_custom_columns', 10, 2 );
Comments
Post a Comment