The title might be a bit vague while I'm not quite sure how to describe it.

What I want:

At every single post (in this case of post type 'event') a logged in user must be able to click a 'Join' button (and when clicked a 'Unjoin' button). The admin must be able to see which users have joined an event and which event. It doesn't matter if this must be a custom field at the User profile info or a new list in the admin.

What I already have:

I have made a custom checkbox list of posts at the User profile info. And I do know how to make a button in at a single post. But it must be connected to this list, so when it's clicked the specific post must be checked at the Users profile page.

I'm not sure what the easiest method is to make this, any idea? It's actually a quite simple function.

Thanks in advance.

2 Answers 2



  1. Add the ability to join/unjoint an event for registered client.
  2. Allow the admin to manage/review easily each event participants.

Here is what I will do for a full management


  • Create a custom meta box that you will attach to your CPT "event". (this meta box will display the name of every person that are linked to the event, also, the remove/add event should be added inside the admin).
  • Modify the CPT saving function to save all your users id inside a variable (table).
  • Attach this variable as a meta tag linked to a post of your custom post type "event".


Once a user is register, you should check if the user has applied to the event and display a join button (join/unjoin should be the same button, only one function).

  • Create a function that will get the event new meta tag information and compare if the user has register to the event. (function should return: yes or no -> useful for latter work )

  • Create a function that will update the meta tag value on the button click event. This function should change the button text by join/unjoin and should update/write the new meta tag variable.

Hope this help, if you have any questions, let me know, I can send you examples.

  • 1
    Thanks for your clear answer. I'll give this a try and let you know if I figured it out.
    – Trekdrop
    Jul 21, 2014 at 15:17

I would create a custom post type of "tickets" - I find it easier to just use a CPT register plugin then remove it. You may prefer to code it yourself in which case plenty of information is available on the Codex.

When that person clicks join use something like:

//first define your post info
$post = array(
              'post_title'     =>  'Ticket for '.$eventname.' ('.date('r').')',
              'post_type'       => 'ticket',
              'post_status'   => 'publish',

$RegisterTicket = wp_insert_post($post, false); // $post defined above

if (empty($RegisterTicket)) return 'Unable to create ticket in our system'; //safeguard to explain or trace errors

update_post_meta($RegisterTicket, 'event_post_number', $theEventPostID);
update_post_meta($RegisterTicket, 'state', 'complete'); // This extra meta can be used to change to things such as 'cancelled', 'refunded'.... anything you want to give extra info to the ticket
update_post_meta($RegisterTicket, 'user', $TheUserID); //to assign the ticket to the user.

This is how I do it as I find using custom posts gives you much more scope to edit and alter the tickets individually and minimises damage during potential corruption - power outs, server issues, whatever!

If you were saving a list of users on the Event Post as a list that is your only shot at saving a potentially long list of UserIDs

Remember to to define all the variables mentioned in the code... Things like $theEventPostID can be easily defined by $theEventPostID = get_the_ID();

EDIT: Apologies I forgot to add anything about management of this. I use Advanced Custom Fields It saves a mountain of coding if you are like me and love chopping and changing bits on your posts and making the end user's experience a little easier! You can add meta-boxes galore and relationship fields - a lot of time saved and one of my favourite plugins.

No problem... With regards to showing the user the list of events signed down for you can write a query function using get_posts:

    $tickets_for_user = get_posts(array(
                                        'post_type' => 'ticket',
                                        'meta_query' => array(
                                                                    'key' => 'user',
                                                                    'value' => $user_id
                                                                    'key' => 'state',
                                                                    'value' => 'complete'
  • Thanks for your answer. I am using ACF for this indeed, thanks for your help.
    – Trekdrop
    Jul 21, 2014 at 15:35
  • No problem - have added something about finding upcoming tickets too just in case you need it.
    – Bysander
    Jul 21, 2014 at 15:50
  • Thanks. I've made it somehow your idea, in my case I made some improvements: 1. I've made the CPT 'tickets', 2. Made an ACF checkbox that is populated by post titles of the program post type, 3. I check if the user already made a post, if so it will update just that post. So for every user I've got 1 ticket with the posts checked. Works great. One question: for the button, do you think I'll need to make it with AJAX? Thanks
    – Trekdrop
    Jul 22, 2014 at 8:02
  • AJAX would be good - not 100% necessary but is nice for end user experience - I always appreciate a good bit of AJAX interaction! You could however just use an easy POST form button with a nonce (nonce important for security!) the hidden fields catching info about user and event (post) number.
    – Bysander
    Jul 22, 2014 at 11:18
  • Well I've got it working almost completely. Only for one thing: As I said I'm using a acf checkbox with the update_field command. The problem is that it won't unchecked anything. Any idea how to do this? I was thinking about a in_array comparison and unset the value out of the array. But not sure if this is the best way. Any idea? Thanks
    – Trekdrop
    Jul 22, 2014 at 18:40

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.