0

I'm building an app that I'd like to use WP as a backend for. There are three layers of data that I have to manage:

Meeting Type Individual Meeting (Many of these in each Meeting Type) Persons Attending Each Meeting

My initial through is to create a Custom Post Type for each Meeting Type (only 4-6), and then user posts for each Individual Meeting. I'm not sure how to deal with the Attendees though, because I need to be able to see all Attendees in a given Individual Meeting, but also all Attendees in a give Meeting Type.

One thing I'm considering is to use Metadata for each post to store the list of Attendees. A 2 layer array, with the top level being the Attendees and the sub-array being all information about each one. Then when the page is loaded to be edited, I could run something to turn it into a table? But I'm not sure how one would view all Attendees in each Meeting Type (CTP).

Any ideas? To be clear, I'm not asking for code but for more general suggestions. Maybe a plugin, or examples/tutorials? I've tried searching Google and haven't found much, and tried asking in #wordpress but didn't get any help.

EDIT:

The number of Individual Meetings is going to grow over time, probably into the hundreds. That's the main reason I'm not planning on using a CTP for each Individual Meeting.

Thanks!

0

3 Answers 3

0

It's an interesting idea you have had and I've done something remotely similar but with companies and employees as a sort of CRM I'm building.

What I've done is go down the plugin route and utilised the WP_List_Table class as it organises things very nicely for me.

What I'm doing is creating a set of companies, in your case I'd say Individual Meetings, and then within each company, I can add people with various bits of data to go with it, so in your case that would be attendees.

I'd then have the "parent" meeting type as an additional piece of meta data or even save it under a custom taxonomy to retain the core functionality of getting the various meeting types with a standard loop and category option.

By using WP_List_Table, it keeps things nicely organised and adds the ability to sort by column with whatever meta data you so wish.

WP_List_Table documentation is severely lacking and the resources via Google searches are all wrong and it was through combining various bits from each article researched I got it all working.

I'd be more than happy to send you the plugin so you can view it in action and it might give you an idea on an approach. Plus, you'll have a good base to start from.

Let me know. :)

2
  • This sounds very promising, but I have zero experience with the WP_List_Table, and with any actual WP data tables. I'd love to take a look at your plugin though! It might be cleaner than trying to get it working using CTPs, Posts, and Metadata. The best way to send would be my email address listed in my profile.
    – Kelderic
    Commented Dec 10, 2014 at 21:34
  • Can't see your email on your profile. Can you drop me an email to [email protected] and I'll ping something back over to you. Tried going through your linked site but it never loads. :( Commented Dec 11, 2014 at 14:24
0

Meetings => Custom Post Type Meeting Type => Custom Taxonomy Attendees => Post Meta (array as described)

To get all Attendees for a Meeting Type, loop through all Meetings in the Type and for each retrieve Attendees. You can push each Meeting's Attendees into a new array to be sorted if needed, than foreach the array to write out the details.

2
  • The number of individual meetings in each Type is going to be large. Over time it could grow into the hundreds. I don't think I want to make hundreds or thousands of CTPs. It might be possible but I think it'll hit performance. To the second half of your answer, it looks like it would work. Might even work better using Posts instead of CTPs.
    – Kelderic
    Commented Dec 10, 2014 at 21:30
  • I meant a single custom post type, with a single taxonomy for the types. Commented Dec 10, 2014 at 22:41
0

I think you can to use

  • a CPT "Meetings" where each post is a meeting, you can handle hundreds or thousands with no problem
  • a Custom Taxonomy "Meetings Type", in this way you can set types for meeting posts. Just like categories for standard posts.
  • a CPT "Attendees" where each post is an attendee. Being posts you can handle hundrends or even thousands of them.

Of course the problem is how to connect "Attendees" with "Meetings", because WordPress doesn't have a way to connect a post type to another one.

First solution: Posts 2 Posts plugin

For this problem a popular solution would be use the Posts 2 Posts plugin. It's a well known plugin, used by tons of people, and even its main author, Scribu, says he no longer supports it, from time to time it gets some commits on GitHub.

If you don't want to use that plugin there are some other solutions, I'll propose one here.

Alternative solution: private taxonomy

WordPress, by default, handles only one kind of many-to-many relation, its the one that is established between posts and taxonomies: you can use that to build your system.

What I suggest is to create an hidden taxonomy, called something like 'meeting_attendees'.

You should register that taxonomy with 'public' argument set to false, something like:

register_taxonomy(
    'meeting_attendees',
    array('meetings', 'attendees'), // both CPTs will support the taxonomy
    array('public'=>false)
);

In this way the taxonomy is registered, but it is hidden from WordPress admin UI.

After that, you should create a term for every meeting post. That can be done using 'save_post' hook. Something like:

add_action ('save_post', function($post_ID, $post, $is_update) {
  if ($post->post_type !== 'meetings' || $is_update) {
    return;
  }
  wp_create_term('meeting-'.$post_ID, 'meeting_attendees');
}, 10, 3);

Than you need to build a metabox that allows you to select Attendee posts from Meeting post creation screen.

On Meeting save/update you have to assign to every selected attendee the same term created for the meeting.

In this way, having a meeting post, you can get the related 'meeting_attendees' taxonomy term with a simple get_the_terms call and so be able to retrieve meeting attendees looking for attendees posts that have that term attached. Something like:

// assuming $meeting_id is the ID of Meetings post you want to get the Attendees for
$meeting_attendees = get_the_terms('meeting_attendees', $meeting_id);

if ( ! empty($meeting_attendees) && ! is_wp_error($meeting_attendees) ) {

  $meeting_attendees_term = reset($meeting_attendees);

  $attendees = get_posts(array(
    'post_type' => 'attendees'
    'tax_query' => array(
        array(
            'taxonomy' => 'meeting_attendees',
            'terms'    => array($meeting_attendees_term->term_id)
        )
    )
  ));
}

In the same way you can retreive all Meetings any Attendee attended:

// assuming $attendee_id is the ID of Attendee post you want to get attended meetings
$meeting_attendees = get_the_terms('meeting_attendees', $attendee_id);

if ( ! empty($meeting_attendees) && ! is_wp_error($meeting_attendees) ) {

  $meetings = get_posts(array(
    'post_type' => 'meetings'
    'tax_query' => array(
        array(
           'taxonomy' => 'meeting_attendees',
           'terms'    => wp_list_pluck($meeting_attendees, 'term_id')
        )
    )
  ));
}

As you can see, using core methods is possible to get Attendee for a Meeting and Meetings for an Attendee in a pretty easy way.

The only effort needed is to create metabox that let you assign attendees to a meeting, but it should be pretty easy and if you need help you can find a lot of examples in this site, and all over the web... (e.g. the example on Codex for add_meta_box function is pretty exahustive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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