从帖子标题中获取 WordPress 帖子 ID [英] Get WordPress Post ID from Post title

查看:39
本文介绍了从帖子标题中获取 WordPress 帖子 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的自定义 WordPress 主题有问题.这有点令人费解,但本质上,我需要做的是通过它的帖子标题获得一个帖子 ID.在伪代码中,它最好是这样的:

I have an issue with a custom WordPress theme I'm developing. It's a bit convoluted, but essentially, what I need to do is get a Post Id by it's Post Title. In pseudo-code it would ideally be something like:

title = "foo";
post_id = get_post_id_where_title_is(title);

提到的标题是一个静态引用,不是从 WordPress 中提取的,它已经存在于页面上.

The title mentioned is a static reference not being pulled in from WordPress, it's already present on the page.

提前致谢.

推荐答案

对于任何偶然发现此问题的人来说,这是一个简短的说明:
get_page_by_title() 现在可以处理任何帖子类型.
$post_type 参数已在 WP 3.0 中添加.

Just a quick note for anyone who stumbles across this:
get_page_by_title() can now handle any post type.
The $post_type parameter has been added in WP 3.0.

这篇关于从帖子标题中获取 WordPress 帖子 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆