Assign posts to taxonomy terms instead of the taxonomy terms to posts?

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).

2 s
2

I think the “Featured Post Manager” plugin will be closer to what you’re looking for:

http://wordpress.org/extend/plugins/featured-post-manager/screenshots/

The language used is somewhat confusing, and it may not work for custom taxonomies (directories) or custom types (people), BUT you can probably take the code and customize it to work for those classes of things instead, as well as updating the language used on the page.

It’s mostly a single PHP file, so you’d just have to look at the code ( http://plugins.trac.wordpress.org/browser/featured-post-manager/trunk/fpmngr.php ) and change a couple things from “category” to “directory” (line 81), and “post” to “person/people” (line 108), etc.

Leave a Comment