get_pung()
云策文档标注
概述
get_pung() 函数用于检索指定文章中已 ping 的 URL 列表。它接受文章 ID 或 WP_Post 对象作为参数,返回 URL 数组或 false。
关键要点
- 参数 $post 为必需,可以是整数(文章 ID)或 WP_Post 对象。
- 返回值为字符串数组(已 ping 的 URL)或 false(如果文章未找到)。
- 内部使用 get_post() 获取文章数据,并应用 'get_pung' 过滤器。
- 从 WordPress 4.7.0 版本起支持 WP_Post 对象参数。
代码示例
$pinged_posts = get_pung( $post->ID );
foreach ( $pinged_posts as $pinged_post ) :
if (!empty($pinged_post) ) {
echo 'Incoming Link: '.$pinged_post.'';
}
endforeach;
原文内容
Retrieves URLs already pinged for a post.
Parameters
$postint|WP_Postrequired-
Post ID or object.
Source
function get_pung( $post ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$pung = trim( $post->pinged );
$pung = preg_split( '/s/', $pung );
/**
* Filters the list of already-pinged URLs for the given post.
*
* @since 2.0.0
*
* @param string[] $pung Array of URLs already pinged for the given post.
*/
return apply_filters( 'get_pung', $pung );
}
Hooks
- apply_filters( ‘get_pung’, string[] $pung )
-
Filters the list of already-pinged URLs for the given post.
Skip to note 2 content
Codex
Example
ID ); foreach ( $pinged_posts as $pinged_post ) : if (!empty($pinged_post) ) { echo 'Incoming Link: <a href="'.$pinged_post.'" rel="external">'.$pinged_post.'</a>'; } endforeach; ?>