Posted: January 20, 2023 at 2:58 am
I wrote a script, where I input a custom invoice number into the answer of a custom questions.
It is working good with one exception. I would like to set the question as an admin question. But in this case it doesn’t work, because there is no answer (only visible for admin) and so I can’t set one.
If I set the question for the user and hide it through css, than I can’t use the custom questions in the message.
Is there a function to initialize the admin question so I can set a new value?
Can you post the code to a gist or Pastebin so I can see what you are doing? You can set it to be private so only EE staff can view the reply if preferred.
Your filtering all of the answers to find the specific answer to a specific question, which you already know the ID of, correct?
But if you already know the Question ID, why not just do it directly for that specific question?
The main problem is that the questions, that are set as “admin questions” in WordPress, don’t show up in the following query.
Because the query is giving my an empty array I can’t use the set_value($new_value) method.
Ok, so that’s not actually correct.
Admin-only questions will not have answers generated for them on front-end registrations, because they are admin only questions and will only generate an answer when an admin has edited the registration.
So the reason the above query does not return an EE_Answer object, is there is no answer to generate yet.
Will return an EE_Answer object for admin-only questions if there is something actually saved for those answers, on a front-end registration there will not have been anything saved.
You can confirm this yourself by editing one of those registrations and in the ‘Registration Form Answers’ section, edit the group with the admin-only question, don’t set a value and just hit ‘Update Registration Questions’, like this: https://monosnap.com/file/JVudJVeFB1JFYtp1ofXxN5EBKx22Eh
Now run either/both of the methods from above and you’ll have an extra EE_Answer object.
As you already know the QST_ID and the REG_ID, why not just generate the answer directly?
Obviously, do all of your own checks to confirm the question is actually an admin_only question and does not already have its own value (so you don’t overwrite a value set in the admin already) etc
that is exactly what I was looking for. Thank you for your help.
You’re most welcome