我认为您可以通过以下方式实现这一目标:
1.通过使用get_post_types()
外汇
它根据您传递的参数返回帖子名称或对象的列表
<?php
$args = array(
\'public\' => true,
\'_builtin\' => false
); //pass parameter to array according to get all custom post types( parameter pass for demo only.modify it to get desire result)
$post_types=get_post_types($args,\'names\');
?>
2。发布时向自定义帖子类型添加操作
<?php
foreach($post_types as $post_type){
add_action( \'publish_\'.$post_type, \'ravs_notify_published_post\' );
}
function ravs_notify_published_post( $post_id ) {
$post = get_post( $post_id );
// Here\'s the magic
Wp_Heartbeat_Notify::notify( array(
\'title\' => \'New Post by \' . $post->post_author,
\'content\' => \'There\\\'s a new post publish, why don\\\'t you <a href="\' .get_permalink($post_id). \'">give it</a> a look?\',
\'type\' => \'info\'
));
}
?>
Updated
创建插件以显示实时通知
WP-Realtime-NotifyEdit
粘贴此代码
functions.php
.它将打印自定义帖子类型的名称数组。转到
get_post_types 并查看所有参数。通过提供所需输出的正确参数(更改
$args
).如果您获得了所需的自定义帖子类型名称的正确数组
$args
,用我的
$args 插件中。
<?php
add_action(\'the_content\',\'ravs_customPostList\');
function ravs_customPostList(){
$args = array(
\'public\' => true,
);
$post_types = get_post_types($args,\'names\'); //get names of post types
print_r($post_types);
}?>