0

我正在尝试从附件页面 url 获取附件的 id。

创建自定义帖子时,我将媒体上传到帖子。

媒体现在有一个附件页面 - http://localhost/site/custom-post/post-name/screenshot_20211005-091742/

如何从此网址获取附件 ID?我已经尝试过该attachment_url_to_postid功能,但这似乎只适用于直接媒体网址,例如 http://localhost/site/wp-content/uploads/2021/10/Screenshot_20211005-091742.png

我还测试了直接上传到媒体库的媒体 http://localhost/site/wp-content/uploads/2021/10/S036662860_0.jpg 但attachment_url_to_postid返回 0。

在此处输入图像描述

4

1 回答 1

1

您可以使用url_to_postid而不是attachment_url_to_postidlocalhost/site/custom-post/post-name/screenshot_20211005-091742/ 是页面 URL,而不是直接文件 URL。

于 2021-10-13T08:54:15.233 回答