Reputation: 11
I want to trigger a function in my Wordpress when a scheduled custom post will publish. Unfortunate there is no default action hook for custom_post_type
.
Here is the sample code of my plugin:
function connectwpblog123 () {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
$post_status = 'publish';
$movie_post1 = array();
$movie_post1['post_title'] = 'Schedule Test Example';
$movie_post1['post_type'] = 'fbtweets';
$movie_post1['post_content'] = 'Abce defgh i gk lmno p qr st';
$movie_post1['post_status'] = $post_status;
$movie_post1['tags_input'] = array(1);
$movie_post1['post_category'] = array(1);
$post_id = wp_insert_post( $movie_post1 );
}
add_action('publish_future_fbtweets', 'connectwpblog123', 10, 1);
When I hook my custom post using publish custom post hook:
add_action('publish_post', 'connectwpblog');
This triggers the function for infinite time.
Upvotes: 0
Views: 2199
Reputation: 1114
To use publish_post with any post type:
add_action( 'publish_' . $_POST['post_type'], 'your_func' );
Upvotes: 1