Support

Home Forums Event Espresso Premium Replacing slug on espresso_event post type does not allow the post to be publish

Replacing slug on espresso_event post type does not allow the post to be publish

Posted: November 1, 2018 at 5:29 am

Viewing 5 reply threads


ARAGATO

November 1, 2018 at 5:29 am

I would like the post slug of events to be generically generated from the post/event title + the first datetime.
E.g.
Event: Badminton
Datetime: 2018-12-12 12:44
Slug: badminton-2018-12-12-12-44

So far the slug is generated correctly.
http://uploads.aragato-server.net/screenshots/201811012987f0ca55.png

I am using the action hook: wp_unique_post_slug

In the corresponding callback function I get the event and datetime and recreate the slug:

        if ("espresso_events" == $post_type) {

            //Get event from post id = event id
            $event = EEM_Event::instance()->get_one(
            array(
                array(
                    'EVT_ID' => $post_ID
                    )
                )
            );

            if ($event) {
                //Create slug based on event name and first datetime day and time
                //Get event day from first event day in this particular event
                $datetime = $event->get_first_related('Datetime');

                //Get event name
                $slug_event_name = $event->get('EVT_name');

                //Get RFC 2822 formatted date
                if ($event->get_first_related('Datetime')) {
                    $slug_datetime = date("U", strtotime($datetime->start_date_and_time()));
                } else {
                    $slug_datetime = "no-datetime-".md5(time());
                }

                //Sanatize title to remove unwanted characters
                $slug = $slug_event_name . '-' . date('Y-m-d H-i', $slug_datetime);
            } else {
                $slug = 'new-event-slug' . md5(time());
            }
        }

        return sanitize_title($slug);

That works, as the slug is generated correctly.

However, when I hit publish the event does not get published. It says it get published, but does not.
http://uploads.aragato-server.net/screenshots/201811016941cf2a4f.png

What is wrong? How to solve that mystery? Thanks.


Josh

  • Support Staff

November 1, 2018 at 9:15 am

Hi,

I’m not quite sure if your code is going to do what you’re expecting it to do. For example, in this conditional:

if ($event) {
you’re not checking a boolean there, so that should be changed to:
if ($event instanceof EE_Event) {

You might also check to see if there are other plugins adding filters to wp_unique_post_slug as well, they may be interfering.


ARAGATO

November 1, 2018 at 10:30 am

Basically, what I am trying to achieve is the following:

We have events that have the same title, e.g. “soccer” but on different datetimes and different venues.
Example:
Soccer – Datetime is monday 8pm to 9pm – venue A
Soccer – Datetime is monday 9pm to 10pm – Venue B
Soccer – Datetime is tuesday 8pm to 9pm – Venue C

Although I can assign multiple datetimes to one event, there can only be one venue assigned to the event. Therefore, we have one event for each datetime + venue. In the example above we have three events, each with its own single datetime.

Now the reason for the slug manipiluation. I want to avoid having event slugs like, soccer, soccer-1, soccer-2. But instead, I would like event slugs like soccer-datetime, e.g. soccer-2018-12-31-20-00. Therefore slugs are more accurate.

I only have EE plugins and my own plugin running.
As ssaid, the slug is already generated correctly, however, the event will not publish. It stays inactive although there is a message event has been published. So something is not quite right.
http://uploads.aragato-server.net/screenshots/201811016941cf2a4f.png


Josh

  • Support Staff

November 1, 2018 at 10:46 am

So if you remove your custom code for changing the slugs, the event will publish as expected?


ARAGATO

November 1, 2018 at 10:49 am

yes, it will.


Josh

  • Support Staff

November 1, 2018 at 11:10 am

The code you’ve shared here doesn’t prevent events from publishing on my site, so another thing you could check is to see if that code alone, with no other code from your own plugin running, prevents the events from publishing. It may also help to switch to the default WP theme while troubleshooting this.

Viewing 5 reply threads

The support post ‘Replacing slug on espresso_event post type does not allow the post to be publish’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso