【发布时间】:2020-05-06 20:32:16
【问题描述】:
我正在尝试更改找到here 的插件。这是一个关于组装插件的 Twillio 教程,该插件在使用他们的系统“发布”WordPress 帖子时发送 SMS。我面临的障碍是每天都会生成很多帖子,我不希望多条短信发出。那会很烦人。因此,我创建了一个名为“SMS”的自定义帖子类型。我无法将描述的插件配置为使用自定义帖子类型,而不是初始配置中提供的默认或“帖子”wordpress。
// Prepares SMS to be sent when post is published
// function post_published_notifications($ID, $post ) //Original plugin function. I'm unsure of how to reassign global $post
function post_published_notification($ID) // I added this trying to access CPT, sans $post
{
$sid = '####################';
$token = '######################';
$from = '+1530#######';
$client = new Client($sid, $token);
$gallery_args = array(
'post_type'=> 'SMS',
);
$posts_display_gallery = get_posts( $gallery_args ); // My code that doesn't work. Trying to access the CPT named SMS
$title = $posts_display_gallery->post_title; // My code that doesn't work. Trying to assign variable to CPT title.
//$title = $post->post_title; // gets post title. Provided by Twillio. Returns post title.
$body = sprintf('New Post: %s', $title);
$blogusers = get_users('blogid=$ID&role=subscriber');
foreach ($blogusers as $user) {
$to = get_user_meta($user->ID, 'mobile', true);
if (intval($to) == 0) {
continue;
}
$client->messages->create(
$to,
array(
'from' => $from,
'body' => $body // Custom post type title should be held here.
)
);
}
}
add_action('publish_post', 'post_published_notification', 10, 2);
【问题讨论】:
-
如果
post_title属性正确,你能检查$posts_display_gallery吗?
标签: php wordpress custom-post-type