Is there a way to clean a custom field and display it?
I have this single line text cf with the value (added by user): "Nice & Good Title" and I would like to transform it to "nice-good-title" so I can use it in HTML attributes.
All this inside a view using cf shortcodes.
Any idea?
thanks
It's not natively possible with Toolset Views to somehow alter a value coming from the database in this way, Toolset only offers a sanitize option for the relevant shortcodes, which will not allow you to customize how the content is actually sanitized, but will follow common WordPress sanitization rules instead.
What you can do is creating a Custom ShortCode with 2 attributes:
"data" and "separator".
Your Custom ShortCode then should expand what comes from "data" (this will be your Custom Field ShortCode), and take that string (Nice and Good Title), then strtolower() it, and replace empty spaces with the "separator" you add to your Custom ShortCode.
This will require the usage of Custom PHP code, using methods as shown here hidden link and hidden link
The ShortCode itself can be crafted following the WordPress Codex here https://codex.wordpress.org/shortcode
This ShortCode can then be used in your View, and since it will feature 2 attributes (data and separator) you can then do something like this:
[your_custom_shortcode data="[wpv-post-title]" separator="-"]
That would then process whatever inserted for "data" through your custom code, and strtolower() it, then replace the empty with - using the custom code above linked (adapted to your case).
Please let me know if something is unclear on the general process.