Support

Home Forums Event Espresso Premium Associate question group to an event

Associate question group to an event

Posted: April 7, 2021 at 9:01 pm

Viewing 4 reply threads


make_webmaster

April 7, 2021 at 9:01 pm

I would like to associate a question group to an event but I can’t seem to find the correct model to use. I see event_question_group, but when I look at wp-json it’s showing no args. Is there an easy way to associate a question group to an event if I know the question group ID?


make_webmaster

April 7, 2021 at 9:21 pm

On a side note, I just want to have the same question group applied to each event. I did look at this post but I am confused on where I can specify which question group I want to assign to the event

https://eventespresso.com/topic/set-default-additional-attendees-question-groups-when-creating-event/


Brent Christensen

  • Support Staff

April 8, 2021 at 12:21 pm

Hi make_webmaster,

Are you looking to do this dynamically via the REST API?
If I remember correctly from the last time I helped you, you have full access to the site that Event Espresso is installed on, so it would be easier to do via the hooks that Josh pointed out in that other post you linked to (https://gist.github.com/joshfeck/a70a2ae57e763047b70cafbdd4f61624).

You would just need to place that code into an appropriate place on your site for running code (ex: your theme’s functions.php file, or a custom plugin (best option)) but then change the number in input[value=\'1\'] to match the ID (QSG_ID) of your new question group.

So for example, if you created a new custom question group that had a QSG_ID of 7, then you would need to change that last function in Josh’s code to :

function ee_custom_checkboxes_for_additional_question_groups() {
  echo '<script>jQuery( document ).ready(function($) {
      $("#espresso_events_Registration_Form_Hooks_Extend_additional_questions_metabox input[value=\'7\']")
      .prop( "checked", true );
    });</script>';
}

If you DO want to do this via the REST API, then the request would look something like:

new WP_REST_Request('POST', '/ee/v4.8.36/events/9/question_groups/3');

where 9 would be the ID (EVT_ID) for the event you want to add the relation to and 3 is the ID (QSG_ID) of your question group.

  • This reply was modified 3 years, 7 months ago by Brent Christensen. Reason: added REST API example


make_webmaster

April 8, 2021 at 2:28 pm

Hi Brent, I was able to figure this one out. I am using the model structure and so I was trying to figure out how to pull a certain question group and associate it dynamically to the event.

$qgroups = EEM_Event_Question_Group::instance()->get_one_by_ID(3);
$event->_add_relation_to($qgroups, ‘Event_Question_Group’); //link the question group


Tony

  • Support Staff

April 9, 2021 at 6:23 am

Hi there,

Just a quick note to second that if you have access to the site, go with the models. The EE REST API uses them anyway so you basically cutting out the middleman and doing it directly.

Also, there are methods on the event model to add/remove question groups:

add_question_group($question_group_id_or_obj, $for_primary = false);

and

remove_question_group($question_group_id_or_obj, $for_primary = false)

So if you want to clean the above a little you could switch to:

$event->add_question_group( 3, true);

You’ve already hard coded the ID in the above but don’t state if this is for Primary Registrants or both, if both primary and additional you’ll also need:

$event->add_question_group( 3, false);

Less code and a little more obvious what it is doing but ultimately up to you on what you want to use 🙂

Viewing 4 reply threads

The support post ‘Associate question group to an event’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso