Thank you for sharing the admin access.
I've performed some tests on my website with a similar checkboxes type custom field and here are my findings.
In the code snippet that you've shared few messages back, you're using "get_post_meta" ( get_post_meta($post_id, 'wpcf-has-support-topic', true) ) function to get the value in the "$has_support_topic" variable and then you use it in a condition to check if this value is equal to 1.
But as Toolset Types stores checkboxes type custom field values in a special format in the database, that value is never equal to 1 and hence that condition can never be true.
To fix this, you can use the "types_render_field" function from types to get the checkboxes type custom field value:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
Here is an example of a function hooked to a front-end form that creates a new download post:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action ($post_id, $form_data)
{
// change this 1234 to the actual id of your form
if ( $form_data['id'] == 1234) {
$has_support_topic = types_render_field( "has-support-topic", array( "item" => $post_id ) );
if ( $has_support_topic == 1 ){
// Now create the topic
}
}
}
Note: Please replace 1234 with your actual form's ID and include the code for the BBpress topic creation as needed.
Similarly, if you'd like to also target the back-end downloads post edit screen using the "save_post" hook, the function would look like this:
function my_save_post_downloads_action( $post_id ) {
// If this is just a revision, stop.
if ( wp_is_post_revision( $post_id ) ) {
return;
}
if ( isset($_POST['wpcf']['has-support-topic']) && (!empty($_POST['wpcf']['has-support-topic'])) ){
// Now create the topic
}
}
add_action( 'save_post_downloads', 'my_save_post_downloads_action' );
Important note: Your logic of using the "has-support-topic" field to insert a new topic from the downloads post automatically should be fine for the case of a front-end form that creates a new download post, as the function attached to it will only execute once (i.e. at the time of download post creation ).
However, if you'll later link a similar function to a front-end form that edits a download post or use a function hooked to a back-end downloads post edit screen using the "save_post" hook, you'll end up with multiple support topics created for a single download post every time post is edited with "has-support-topic" field checked.
To avoid that, you can include a new single-line field for example "created-support-topic" along with the "has-support-topic" field in which the ID of the automatically created topic can be saved. This way, you'll be able to track that a support topic has been created for this particular download already and it shouldn't be created again.
I hope this makes sense.