在 Wordpress 中,post_parent 返回 0 [英] In Wordpress, post_parent returns 0
问题描述
我刚刚开始定制我自己的 Wordpress 网站.我在 PHP 编程方面有一些经验,但我无法让这个工作.
I just started customizing my own Wordpress website. I have some experience in PHP programming, but I can't get this one to work.
使用 wp-types 插件,我创建了父子关系.当我请求父的 ID 时,它总是返回零:
With the wp-types plugin I created a parent-children relationship. When I request the ID of the parent, it always returns zero:
echo "Parent PostID: " . $post->post_parent . "<br>";
wp_get_post_parent_id 函数也是如此.
This is the same for the wp_get_post_parent_id function.
非常感谢您的帮助.
推荐答案
post_parent
是 WordPress 的核心功能,与 Types 插件中设置的父子关系无关.(类型中的关系存储在帖子的自定义字段中.)
The post_parent
is a WordPress core feature, and isn't related to the parent-child relationships set up in the Types plugin. (The relationship in Types is stored in custom fields on the posts.)
A 类型支持论坛上的帖子建议 建议使用此方法在类型中查找帖子的父级:
A post on the Types support forum suggests suggests this method for finding the parent of a post in Types:
$parent_id = wpcf_pr_post_get_belongs(get_the_ID(), 'parent-type-slug');
if (!empty($parent_id)) {
$parent = get_post($parent_id);
}
(反过来会更容易一些,因为有一个 types_child_posts
方法,用于返回帖子的类型子级.)
(It's slightly easier to go the other way around, as there's a types_child_posts
method for returning the Types children of a post.)
这篇关于在 Wordpress 中,post_parent 返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!