Support » Fixing WordPress » “parent_id” doesn’t work if filled manually

  • Hi,
    I created a hierarchical custom post type that has thousands of posts.
    I want to assign parents to some posts.

    Due to the large number of posts, finding the parents from the “Page attributes” dropdown is not practical.

    Therefore, I thought of adding the “parent_id” in the “custom fields” section, and fill in the post id of the parent post.

    However, when I do so and publish/update the child posts, I find the dropdown list in the Page attribute section still reads (No parent).

    So How to specify the hierarchical post parent without having to scroll through thousands of lines trying to spot it?

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry for the slow reply. By whatever means, the post’s record in the posts DB table needs to have the parent ID set in the “post_parent” field. Adding it to custom fields will not accomplish that without extra coding. For example, there is an action that can be hooked when custom fields are saved. Your added code could check for any field input named “parent_id”, and when found, set the appropriate field in the post’s DB record.

    If the only editing you are doing is for setting the parent, the quick edit dialog will be faster and easier. It’s possible to add custom settings to the quick edit dialog. When the post is updated, added code saves the ID directly without needing to check custom field data. See Plugin API/Action Reference/quick edit custom box

    There are similar actions for the main edit screen if you prefer a similar direct field there instead of relying on custom fields.

Viewing 1 replies (of 1 total)
  • The topic ‘“parent_id” doesn’t work if filled manually’ is closed to new replies.