So I have a custom post type (people) with a related custom taxonomy (directory). Instead of editing a person and then choosing the related directory organizations I’d like to “edit” a directory org and choose the people that belong to it. Anyone know of a plugin that allows this?
I could build my own plugin with an interface to do this – looking for opinions here to. Thinking of doing something like:
<?php
//Get all directory orgs
$orgs = get_terms("directory");
$count = count($orgs);
$orgtermids = array();
$peopleByOrg = array();
if ( $count > 0 ){
foreach ( $orgs as $org ) {
$orgtermids[] = $org->term_id; //Build array of term_ids
$peopleByOrg[$org->term_id] = array(); //Build an empty array() for each term_id
}
}
//Get all people currently associated with a directory org
$myquery['tax_query'] = array(
array(
'taxonomy' => 'directory',
'terms' => $orgtermids,
'field' => 'term_id',
)
);
query_posts($myquery);
if (have_posts()) : while (have_posts()) : the_post();
$postOrgs = get_the_terms($post->ID, 'directory'); //Get directory orgs for this person
if ( $postOrgs && ! is_wp_error( $postOrgs ) ) {
foreach ( $postOrgs as $postOrg ) {
$peopleByOrg[$postOrg->term_id][$post->ID] = $post; //Store person info with each org it belongs to
}
}
endwhile;
endif;
//Step through and create interface to choose additional people for each directory org
//code TBD
?>
Any ideas or opinions?
Just thought of a better way to do this by extending the Walker class with a new class based on Walker_Category. I’d have to modify this to create a form where people could be assigned to directory orgs instead of displaying as a list (directory orgs are hierarchical).