Yes, it possible to set a post of one type to be a child of another type of post. You just need to make sure that the post_parent
parameter is passed along other post data (post_title, etc.) when the post is created / inserted in to the database.
For example, if you have a custom form for submitting the applications, you could add the job post ID in a hidden field to it.
<form id="yourApplicationForm" method="post">
<!-- form fields -->
<input type="hidden" name="job_id" value="<?php echo esc_attr( $job_id ); ?>">
<!-- submit button -->
</form>
When the form is submitted and the data is passed to your form handler, you’d grab the hidden field value from $_PSOT
and set it as the post_parent
value.
function your_form_submission_handler() {
// code..
// insert application post to database
$application_post = wp_insert_post(
array(
// other_post_field_keys_and_values,
'post_type' => 'application',
'post_parent' => absint( $_POST['job_id'] ?? 0 ),
)
);
// code..
}
WordPress will happily accept the job ID as post_parent
even, if the ID is for a post of another type.
If, on the other hand, you’re using some plugin or theme feature for the application form, then the idea stays the same, but the implementation might require a little more digging.
Basically, you would still add the job ID to the form as a hidden field, but you would need to find out how the form is saved, and how you can filter the form data to map the job ID as the post_parent
for the application post.
If the form functionality also uses wp_insert_post
in the end to save the submission as a post, you could then either use wp_insert_post_parent
or wp_insert_post_data
filters to set the post_parent
from $_POST
.