钩子文档

attachment_url_to_postid

💡 云策文档标注

概述

attachment_url_to_postid 是一个 WordPress 过滤器,用于在通过 URL 查找附件 ID 时进行过滤。它允许开发者修改或干预附件 ID 的查找结果。

关键要点

  • 过滤器名称:attachment_url_to_postid
  • 参数:$post_id(int|null,函数找到的 post_id)和 $url(string,被查找的 URL)
  • 返回类型:int,通过 apply_filters 应用过滤器后的附件 ID
  • 相关函数:attachment_url_to_postid(),位于 wp-includes/media.php,用于尝试将附件 URL 转换为 post ID
  • 引入版本:4.2.0

📄 原文内容

Filters an attachment ID found by URL.

Parameters

$post_idint|null
The post_id (if any) found by the function.
$urlstring
The URL being looked up.

Source

return (int) apply_filters( 'attachment_url_to_postid', $post_id, $url );

Changelog

Version Description
4.2.0 Introduced.