I’m not sure if this is a bug with FES or something I’m doing wrong. Since I haven’t seen other reports of it, I’m wondering if it’s something I did.
I have a Front End Form that includes the Event Category field. It is marked Required, has no description or class, and users are not allowed to add new categories. I have front end editing enabled.
When I edit an existing event, the event category does not pre-populate with the saved value. I know the event has a category because when I view it on the admin side, I can see the category in the Event List and also when I edit the event on the admin side, the category is selected.
For some reason, line 319 of front-end-edit.php:
$terms = get_the_terms( $event_id, $taxonomy );
is setting $terms to false.
I do have a plugin that adds a custom taxonomy to the event CPT with the following code:
register_taxonomy_for_object_type( 'troop', 'event');
So I thought that might be causing the issue but I have commented it out and the issue still remains.
Thoughts?
Christie Speich
Hi Christie,
When that line is reached is $event_id
and $taxonomy
what you would expect (the event’s ID and event-category
)?
I’ve tested this and it works for me, so I’m trying to determine if the issue is with the get_the_terms()
function or, if the function is not being passed the appropriate values.
Stephen Harris
Yes to both. I verified the event ID is the id of the event I’m editing.
It seems highly unlikely that a core WP function is causing the problem. That’s why I’m thinking it has to do with my custom taxonomy? But I don’t know why adding a custom taxonomy would cause a problem…?
Thanks!
Christie Speich
I would agree that a custom taxonomy is very unlikely to cause this.
Unfortunately the only way to determine what is to step through the code and see where it deviates from expected behaviour. One thing to check is the SQL command that is run to ensure that is what we’d expect.
If that’s the case, then its a third-party is changing something via filter. If the SQL is different from what you’d expect, then again that could only be a third-party filter.
Given the categories appear correctly elsewhere, it’s certainly not a database issue. There must be some runtime logic in a third-party that is preventing get_the_terms()
returning the categories.
Stephen Harris
Indeed, it was a filter, one of my own. facepalm
I added a custom term meta to the venue taxonomy. I need to be able to filter the drop down list of venues on the front end form based on that term meta.
I could not find a suitable filter in FES so I used get_terms_args
and set meta_key
and meta_value
if $args['taxonomy'][0] == 'event-venue'
.
Problem was, the query was running for both event-venue
and event-category
, and as event-category
does not use the term meta I added, it was failing to return anything.
So, what I ended up doing was changing line 1626 of class-eo-event-form-element.php
to include the necessary meta_key
and meta_value
as an argument to eo_get_venues
.
Obviously editing the core EO plugin files is not the best solution. Do you have another idea for being able to filter the venue list?
Thanks!
Christie Speich
The simplest solution would be to copy the file eo-event-form-event-venue.php
from templates/elements/
into your theme, and edit it there.
Specifically the ‘options’ argument in line 10 (which is assigned the value returned by $this->element->get_venues()
) is provided with an array of venue names, indexed by venue ID. Simply remove the undesired venues from that list.
Stephen Harris