In Wordpress, post_parent returns 0

2019-07-24 01:00发布

I just started customizing my own Wordpress website. I have some experience in PHP programming, but I can't get this one to work.

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>";

This is the same for the wp_get_post_parent_id function.

Help is very much appreciated.

标签: php wordpress
1条回答
放我归山
2楼-- · 2019-07-24 01:47

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 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);
}

(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.)

查看更多
登录 后发表回答