I am using a custom check box field to store self reported expert skills in the user registration form i.e. experts who join the site will select skills from a list of checkboxes.
The data is stored fine in the system but when I try to retrieve it the name of associative array is a random variable which I cannot predict, which makes we wonder how do I get the data out of the database when the name of the field is not standard.
I have attached screenshot of the array output and the checkbox setup. Your help would be appreciated.
Array:
Array ( [wpcf-fields-checkboxes-option-1892718e260b6e693c5b2cd1a993efd6-1] => Array ( [0] => Listening ) [wpcf-fields-checkboxes-option-1099a5c3b340cd1a224142fdb234a813-1] => Array ( [0] => Writing and presentation ) [wpcf-fields-checkboxes-option-ce4d50746eb26cb49c31b7ddea040944-1] => Array ( [0] => Negotiation ) [wpcf-fields-checkboxes-option-f0fcbcd04d95febd254ba6632af47a70-1] => Array ( [0] => Market analysis ) [wpcf-fields-checkboxes-option-174dbf46140bf275c75afa82c4fcf418-1] => Array ( [0] => Metrics definition ) [wpcf-fields-checkboxes-option-ca025c7e8ae6c05abd773c33aa016c01-1] => Array ( [0] => Feature prioritization ) [wpcf-fields-checkboxes-option-23ba1f7ad604b84a39d2d85bf5192100-1] => Array ( [0] => Build vs buy vs partner ) [wpcf-fields-checkboxes-option-970e65410cc01150814f2427d548d8f3-1] => Array ( [0] => Product roadmap ) [wpcf-fields-checkboxes-option-48efb068b25a2319382d5cb2b62f9084-1] => Array ( [0] => Business model design ) [wpcf-fields-checkboxes-option-bfdb74157d9228c8701b6491c36c0b71-1] => Array ( [0] => Product vision ) [wpcf-fields-checkboxes-option-d1fbdaf26abe9b252c94573d0790ac7e-1] => Array ( [0] => User feedback review ) [wpcf-fields-checkboxes-option-9cdd22266ae99086c22a6da638cbf639-1] => Array ( [0] => Wireframes and mocks ) [wpcf-fields-checkboxes-option-399eadf816bdddd5bfcd0a6c7c470738-1] => Array ( [0] => User research ) [wpcf-fields-checkboxes-option-b155ddfcdde3405a058738cdd57ea134-1] => Array ( [0] => User journey and personas ) [wpcf-fields-checkboxes-option-077c24304b72a0c840c519ddd71adb48-1] => Array ( [0] => Database structure ) [wpcf-fields-checkboxes-option-05cd65b9c6d871ff137497c408c6892c-1] => Array ( [0] => API integration ) [wpcf-fields-checkboxes-option-2fedfab07c9f53f92bd8ce113f37ecb4-1] => Array ( [0] => Data retrieval ) [wpcf-fields-checkboxes-option-3a007358010ddf0bd6c757575997d0de-1] => Array ( [0] => Performance tracking ) [wpcf-fields-checkboxes-option-45eeae415f13ce869e7e1329c23068ac-1] => Array ( [0] => Agile methodologies ) [wpcf-fields-checkboxes-option-82e22fa54289cc451b1c7b6fa5b81531-1] => Array ( [0] => Relationship building ) [wpcf-fields-checkboxes-option-23739ed48a0d2dc3239e44ad5e012542-1] => Array ( [0] => Stakeholder alignment ) [wpcf-fields-checkboxes-option-44f8607bde9d400f96cdacb72361259f-1] => Array ( [0] => Marketing collateral ) [wpcf-fields-checkboxes-option-58a0248a1e447d30b2dd51cebe927ebe-1] => Array ( [0] => Sales training and support ) [wpcf-fields-checkboxes-option-55c837b1d81c07410737f1bb39fb06d5-1] => Array ( [0] => Market positioning ) [wpcf-fields-checkboxes-option-7fd767df624919459b0dde443551b89e-1] => Array ( [0] => Pricing strategy ) )
Hello and thank you for contacting the Toolset support.
Can you try with Types functions instead of WordPress function. Check this article and the examples there https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
If you need to get the labels for the checkboxes, use the shortcode suggested by Nigel here https://toolset.com/forums/topic/get-all-custom-fields/#post-1901363
I hope this helps. Let me know if you have any questions.
Jamal,
Strangely, the types field shortcodes returns no data even if data exists (see screenshot).
Shortcode: [types field="expert-self-reported-skills" user_is_author="true" separator=", "][/types]
I also tried one with wpcf- as prefix but no data.
[types field="wpcf-expert-self-reported-skills" user_is_author="true" separator=", "][/types]
This shortcode is added on a post created by the author and checkboxes are stored in the custom user field.
What if you used the wpv-post-author shortcode:
[wpv-post-author format='meta' meta='expert-self-reported-skills']
Or if you pass the user ID in the item attribute:
[types field="expert-self-reported-skills" separator=", " item="[wpv-post-author format='meta' meta='ID']"][/types]
If this does not help, please allow me temporary access to your website and add links about all the involved elements:
- URL on the frontend where we should see this.
- Content template or View.
- Custom field definition.
- The post or user to test with.
Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
I was able to display the post's author's skills using types shortcode and usermeta attribute. Check this screenshot hidden link
[types usermeta='expert-self-reported-skills' separator=', ' user_is_author='true'][/types]
Does this answer your question? Am I missing something else?
My issue is resolved now. Thank you!