I have two custom post types set up in Types: Projects and Proposals. Proposals is a child of Projects. I have created a CRED form for proposals and placed it in the Project content template. I am using custom code to automatically populate the Parent field, so I have hidden this field from the CRED form. See custom code below:
function my_save_data_action_1($post_id, $form_data) {
// If a specific form
if ($form_data['id']==550 {
//Get the ID of the Post where the CRED is in (parent post id)
$parent_post_id = $form_data["container_id"];
//get the post type of the post where the CRED is in (parent post type)
$type = $form_data['post_type'];
//redefine the meta_key for the parent post id in the current edited/created Child Post
$our_new_wpcf_belongs_parent_id = "_wpcf_belongs_".$type."_id";
//update this field with all data
update_post_meta($post_id, $our_new_wpcf_belongs_parent_id, $parent_post_id);
}
}
add_action('cred_save_data', 'my_save_data_action_1',10,2);
When I view the Proposal in WordPress, the parent field is correct and has been updated using the custom code.
Here’s the problem: I have created a view that will display a list of all proposals for a project. I am trying to insert the title of the parent project within this view, and I am also trying to link each item in the loop to the parent project.
Here is what I am using:
[wpv-post-title id="$legal-scout-project"]
Initially, this does not work. It just displays the title of the proposal, instead of the title of the project.
If I view the proposal in WordPress, make no changes, and then click update. The post title in the Proposals View then shows the correct title, which is the title of the Parent Project.
Manually updating the proposal in WordPress each time a proposal is submitted is not an option.
Any ideas on how this could be fixed? Thanks in advance!
Was the relationships created through types ? Meaning if I go to one of the Post I would see the associated Parent with it ? Or is it that you just have this hidden field on the posts.
Yes, this relationship was created with types. I auto-generated the form, and I am using css to hide the field where you select the parent item, since it automatically populates using custom code. If I view a proposal, there is a field for the parent project.