我正在尝试从附件页面 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。