WordPress函数generic_ping()向所有订阅了ping服务的站点发送ping,通知它们有新的内容更新。该函数通常在发布或更新文章时调用,以确保订阅了ping服务的站点能够及时获取到最新信息。

generic_ping( int $post_id ): int

函数参数

$post_id

数据类型:int (必须)

文章ID。

函数返回值

返回$post_id。

函数使用示例

在每次发布新文章时自动发送ping:

function send_ping_after_publish( $post_id, $post, $update ) {
    if ( ! $update && $post->post_status == 'publish' ) {
        generic_ping( $post_id );
    }
}
add_action( 'save_post', 'send_ping_after_publish', 10, 3 );

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章