我想在预定的自定义帖子发布时在我的Wordpress中触发一个功能。遗憾的是,custom_post_type
没有默认操作挂钩。
以下是我的插件的示例代码:
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);
当我使用发布自定义帖子钩子挂钩我的自定义帖子时:
add_action('publish_post', 'connectwpblog');
这会触发无限时间的功能。
答案 0 :(得分:1)
将publish_post用于任何帖子类型:
add_action( 'publish_' . $_POST['post_type'], 'your_func' );