admin管理员组

文章数量:1122832

I have a hierarchical custom post type, let's say kitchen. Each kitchen (post) can have multiple children (variants) representing colors. Major parts of the information will probably be stored in metadata fields (ACF).

The main reason behind this is that the client needs unique urls and image gallery for each color, /kitchen/ocean-blue. Most parts of the child page would then contain the same information as the parent but have another title, featured image (post_thumbnail), image gallery and color relationship (custom taxonomy term) and maybe some minor differences in text.

My goal is: whenever a kitchen child post is created, all data from the parent should be copied and pre-filled on the child post. I have a regular PIM system in mind where all fields are inherited and also synced to the parent, and updates when the parent updates, unless you choose to unlock them (seprarately).

Since there's no way to know if you're creating a kitchen or a variant when clicking "Add new" I'm leaning towards a solution with a custom "create color variant" button or link on each post row in the edit screen.

Suppose I can manage to do the first part. How can I then, in the best way, copy all the data? If I do a custom wp_insert_post() I would also have to try to update child post parts when updating the parent (kitchen) and this would not be easy I guess.

Or would I have to rethink this to pre-decide what fields should be available and then get the parents field's values in the child front-end template? Maybe the best solution in this case would be to not copy any information from the parent when creating the child and instead do all the work in front-end: let the child template show all fields/data from the parent unless the template can find a value in the same field on the child (querying each field more or less separately).

Or should this be done with Gutenberg Blocks and use the Gutenberg lock and sync functionality in some way?

How would you go about it? Has anyone created something similar/a PIM-system with WordPress? Any thoughts on this matter is highly appreciated.

本文标签: syncHow can I clonecopy all fields (post and meta) from parent CPT post to child (with synced fields)