degami
Forum Replies Created
-
@timafeo – glad you got it (mostly) working.
@roosalles – agreed: great plugin, wish it had better developer docs.I’m afraid I never properly resolved the issue and couldn’t get the field to display on the front-end. But, I did eventually create a stupidly complex workaround…
Ultimate member has a field type ‘shortcode’ that lets you add the output of a WordPress shortcode into the form. So, I created a custom shortcode (link to gist) to display any piece of user metadata I wanted.
Then, I added a shortcode field just below the field with the choices callback, and used my
[USERMETA meta='cities']
shortcode. I set this new field to only display on view, to give one field that lets the user update the city value in Edit mode and one field to display the city in View mode.But, the shortcode doesn’t display a nice field header like other fields do, so I also added a “Content Block” field to act as a header.
(Actually, my first attempt was to put the shortcode directly into the Content Block, but it that didn’t parse the shortcode properly. I guess this is why they have a separate Shortcode field-type.)
So the final workaround has 3 fields – the original dropdown select field with the choices callback, a shortcode to display the value on the front end, and a content block to give the value a header. Kinda ridiculous, but it works! (Until they fix the issue in an update and I’m left with duplicated fields everywhere… haha)
~D
Hi,
I’m also exploring the choice callback feature and have found very little documentation. In case you’re still looking (or if someone else follows this path), I’ll add what I’ve learned here:
It appears you need to write your own callback function and put it into the
functions.php
script of your theme. The function needs to return an array, and I found that a key-value pair array gave me the most control over the options that are returned.I managed to get a simple example working with 2 dropdown fields:
1. “countries” – just a standard dropdown field with options predefined
2. “cities”:
– Choices Callback = “getCities”
– Parent = “cities”Then, I added my getCities callback to my child-theme’s functions.php file:
The $cities array is returned, and my field “cities” is populated with the options from that array.
The issue I now have is that I can’t get my field with a Choice callback to display on my profile page – the field’s visible in edit mode, and saves correctly to the wp_user-meta table of the database, but won’t show in ‘view’ mode. I’ve double checked the “visibility” option for the field, and it’s set to View Everywhere. As soon as I remove the choice callback and parent field, it’s visible. Anyone know of a solution to this?
~D.
- This reply was modified 8 years ago by degami. Reason: fixed gist link