-1

I need to allow comma in custom taxonomy, when I add some values in the administration.

I have a custom taxonomy "Location" and want to add this kind of value : "New York, NY" from a post. But if I use comma, WordPress splits my value into 2 terms. It works only if I add a value from the taxonomy page:

I tried the solutions on these posts:

https://wordpress.stackexchange.com/questions/25043/how-can-i-allow-commas-in-tag-names

Commas in WordPress Tags

But nothing seems to work.

Maybe a possible solution would be to replace the "," with a ";" to split multiple terms.

Register taxonomy code:

register_taxonomy(
  'locations',
  'positions',
  array(
    'label' => 'Locations',
    'labels' => array(
    'name' => 'Locations',
    'singular_name' => 'Location',
    'all_items' => 'All locations',
    'edit_item' => 'Edit the location',
    'view_item' => 'See the location',
    'update_item' => 'Update the location',
    'add_new_item' => 'Add a location',
    'new_item_name' => 'New location',
    'search_items' => 'Search for a location',
    'popular_items' => 'Popular locations'
  ),
    'hierarchical' => true
  )
);
register_taxonomy_for_object_type('locations', 'positions');
BSMP
  • 4,596
  • 8
  • 33
  • 44

1 Answers1

-1

One of the things that has helped with me with development is to really learn the hooks and filters involved in the process.

It would take you awhile to dig through the hooks and filters lists to find what would parse the input for this.

This posts answer is marked for a filter for front end only. https://wordpress.stackexchange.com/questions/25043/how-can-i-allow-commas-in-tag-names Same with the other post you added.

There are ways to do this but I honestly wouldn't recommend it. It would be easier to just add it in the backend via the category or taxonomy page itself.

However, if you wish to go down this rabbit hole what you are looking at is more a filter like this. https://developer.wordpress.org/reference/hooks/field_no_prefix_save_pre

That used to be category_save_pre which is responsible for parsing that field for security which is why the , gets removed.

I dug up that hook via just looking for hooks marked category as that is the default taxonomy.

This isn't a good answer but this is a good place to start digging more into it.

https://wordpress.stackexchange.com/questions/185587/updating-a-post-without-escaping-ampersands

I ran out of time digging on this one.

Good luck

Tim Herbert
  • 120
  • 10