wordpress - 根据帖子链接获取帖子ID
问题描述
我想将 Wordpress 帖子链接转换为帖子 ID。例如,我有一个带有永久链接的帖子
site.com/the-first-post
现在我想要这个帖子ID。是否有这样的函数:输出帖子 ID 的 Sample_function("site.com/the-first-post")?
解决方案
Wordpress 具有内置功能,用于在给定其 url 的情况下检索页面/帖子的 id,或在失败时为零。可以认为是 get_permalink() 的反函数。
url_to_postid( site_url('the_slug') ); //the-first-post
您将在此处找到详细信息: https ://codex.wordpress.org/Function_Reference/url_to_postid
推荐阅读
- c# - SmtpCommandException:不正确的身份验证数据未知位置AuthenticationException:535:不正确的身份验证数据
- html - 如何使用 CSS 调整图像大小以适应其容器?
- sql - 列作为用户定义类型和使用 Ref 到用户定义类型之间的区别
- python - pip 无法安装 flask-socketio
- vba - 报告中的访问 VBA 代码为每一行提供相同的结果
- sql - 有没有使用 SQL 缓存的案例?
- python - For-loop 给出输出,当再次运行时显示无
- node.js - 如何将nodejs中的多个文件上传到AWS S3并将文件url保存到数据库中?
- java - 从 Document 文件夹的绝对路径获取 iOS app-private 文件夹库
- azure - 在 Azure 存储资源管理器中浏览大量文件