Problem: I have 3 custom post types. A is related with B, and A is related with C. I have a view with C information and i want to show also B info that are related to A.
Solution: Depending on the types of post relationships, you may also need a View of post type A.
- If A-C is a one-to-many (O2M) relationship and "A" is the parent, you do not need a View of A in this case.
- If A-C is a O2M relationship and "A" is the child, there can be multiple A's related to each C, so you need a View of A.
- If A-C is a M2M relationship, there can be multiple A's related to each C, so you need a View of A, regardless of which is the parent and which is the child.
Problem: I have a Form that creates child posts. If the featured image is not provided in the child post Form, I would like to copy the featured image from the parent post into the featured image of the child post.
Solution: If the parent post is not predefined, then you must use the Forms API to copy the parent post's featured image into the child post's featured image since the parent post cannot be determined at the time the Form is loaded. Use the cred_submit_complete API to automate the process. In that callback you can use toolset_get_related_post or toolset_get_related_posts to query the parent post, then get_post_meta to fetch the featured image, then update_post_meta in the child post to set the featured image programmatically.
Problem: I have two custom post types - Articles and Authors - connected in a many-to-many (m2m) post relationship. I have created a View of Articles posts, and in the list of Articles I would like to include information about the related Author.
Solution: Any time you want to display information from the "many" side of a post relationship, you'll need a View. Since the relationship between Articles and Authors is a many-to-many relationship, you'll need a nested View structure to display a list of Articles and the related Authors for each Article.
Nested View creation is not directly supported in the Block Editor, so you can use the legacy View editor if necessary. For the inner View, use a post relationship Query Filter configured with the Articles - Authors M2M relationship selected, showing items as related to the current post. You can place the inner View in the loop of the outer View using a wpv-view shortcode.
Problem: I have two custom post types in a one-to-many post relationship. Province is the parent (one) and District is the child (many). I would like to generate an export CSV that includes each District title and its parent Province title.
Solution: Go to wp-admin > All Export > New Export. The first step is to choose a specific post type, and choose District as that post type. Then click "customize export file" to move on to the next step. Usually ID, Title and Content are already in place in the builder. You can drag the ID and Content blocks out of the box since you don't want to include those items.
Next click "Add Field" below the builder area to add a new custom column for the Province Title. Choose the option to select a field to export, and select the ID field. You may need to reset the column name information after choosing the ID field. Check the checkbox to export a value from a PHP function, type prov_parent_title in the function name field, and paste this function in the function editor to define the custom prov_parent_title function: