0

Is there a way to generate a custom post type list within the admin of another custom post type and use that information as meta data?

For example, there is one custom_post_type named "Attorney" and another named "PracticeArea". There are approximately 20 PracticeArea posts. On the admin for the Attorney post, a "PracticeArea" metabox would contain a list with checkboxes, generated from the custom_post_type "PracticeAreas". The admin could check mutliple checkboxes, and checking a PracticeArea in the metabox would save the info as meta data in the Attorney post. Adding another PracticeArea post would populate that term in the Attorney metabox.

0

WordPress has a very simple and strict data model: posts and taxonomies. Posts (and their post types) are for content and taxonomies (hierarchical or not) are for grouping or relating those contents.

To get an approach the WordPress way, you might switch your post type into a custom taxonomy Attorney to group your custom post type PracticeArea.

Here is a simple mock up code for e.g. your functions.php to get you started:

add_action('init', 'register_post_types_and_taxonomies');

function register_post_types_and_taxonomies() {
    register_post_type('practice-area', array(
        // Your CPT args
    ));
    register_taxonomy('attorney', array('practice-area'), array(
        'hierarchical'=> true, // Behave like categories (checkboxes)
        // Your CT args
    ));
}

With this, you get your checkboxes. You will get it the other way around (you will have to check the attorney on the practice area) but you can easily display stuff in the front-end. If you create a taxonomy-attorney.php and use the description field as post_content sustitution, you get all related practice areas in your main query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.