Hi, I tried 2 different approaches, but it still hasn't worked.
I tied with cred_redirect_after_delete_action:
add_filter( "cred_redirect_after_delete_action", "prefix_custom_redirect", 10, 2 );
function prefix_custom_redirect( $url, $post_id ) {
log_me('----------DELETE redirect --'.$post_id.'------');
$deleted_post = get_post( $post_id );
if ( $deleted_post->post_type == 'fishes' ) {
log_me('----------fishes---------');
}
return $url;
}
It just does nothing, I also don't get any output of log_me() in debug.log
Then I created an Edit form with the submit button and tried this custom code:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
log_me('----------TRASH--'.$post_id.'------');
if ($form_data['id']==1039)
{
$my_post = array(
'ID' => $post_id,
'post_status' => 'trash',
);
wp_update_post( $my_post );
}
}
It changes the status of the post, but it doesn't remove it from the Repeatable Group and I got this error in debug.log:
[31-Jul-2021 18:58:20 UTC] PHP Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in /public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246
Stack trace:
#0 /public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->set_query_by_elements(Array, 'parent')
#1 /public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/public_api/m2m.php(110): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->__construct(0, 'fishes', Array)
#2 /public_html/wp-content/plugins/cred-frontend-editor/application/models/form/post.php(671): toolse in /public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php on line 246
One last thing, I missed this line, before the conditional IF, in the custom code of the previous message:
$deleted_post = get_post( $post_id );
cheers