Support

Home Forums Event Espresso Premium Create Post on Publish EE Event

Create Post on Publish EE Event

Posted: September 28, 2017 at 6:17 am


ARAGATO

September 28, 2017 at 6:17 am

I would like to automatically create a post (post type page) upon publishing a new event in event espresso.

Since event espresso events are custom post type events it should trigger for the followign code:

function post_publish() {
    // A function to perform actions when a post is published.
        // Gather post data.
        $my_post = array(
            'post_title'    => 'My post',
            'post_type'     => 'page',
            'post_content'  => 'This is my post.',
            'post_status'   => 'publish',
            'post_author'   => 3
        );

        // Insert the post into the database.
        wp_insert_post( $my_post );
}
add_action(  'publish_post',  'post_publish', 10, 2 );

However, it does not.
The code works for normal posts. For example, when I publish a normal wordpress post the snippet is hooked and creates the My post page.
However, it does not work when publishing an event espresso event.
Why not?


Josh

  • Support Staff

September 28, 2017 at 9:43 am

Hi there,

Because it’s a custom post type. The WP Codex explains how to trigger this action for a custom post type:

To trigger this action for a custom post type, use publish_{$custom_post_type}. e.g. if your post type is ‘book’ use:

add_action( 'publish_book', 'post_published_notification', 10, 2 );

https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post


ARAGATO

September 28, 2017 at 11:23 am

Thus, in order to trigger it for an EE Event it would be:

add_action( 'publish_espresso_events', 'post_published_notification', 10, 2 );

Is there a list of all custom post types from EE?


Josh

  • Support Staff

September 28, 2017 at 11:39 am

The action hook name is correct, but you’ll need to change the callback function name of course.

There are two public custom post types registered by the EE plugin:

espresso_events
espresso_venues


ARAGATO

September 28, 2017 at 10:02 pm

Thanks Josh. Solved.

The support post ‘Create Post on Publish EE Event’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  ARAGATO 2 years, 2 months ago ago

Topic Tags

Notifications

This topic is: resolved
Do NOT follow this link or you will be banned from the site!