CRED plugin provides an API, making it easy to customize your post or user forms. The API includes hooks (actions and filters) to accomplish specific tasks using PHP code.
When you ask for help or report issues, make sure to tell us all related information about your form and what you want to achieve.
Viewing 15 topics - 331 through 345 (of 451 total)
Problem:
Hide populated fields when editing a form
Solution:
Edit post form is intended to show the content of the post which you currently edit.
If you remove the field values, then the original field values where even you will not make any change will not be get saved.
we do not advise to mimic with the original edit form behaviour as if we make any changes to it sooner or later there is a chance that it can be broken.
Problem:
The user would like to run custom code when a post is deleted. He tried the cred_redirect_after_delete_action action but it does not help him.
Solution:
Because we need to do some logic that depends on the post data, which is already deleted at this stage, we need to use another action/filter.
We suggest using a Post Edit form that will change the status of the post to "Trash" and rely on the cred_save_post hook.
Problem: I have a Commerce Form that is used to publish a post and connect it to an Order. The Commerce Form is configured to publish the post when the Order is completed. However, sometimes clients submit the same Form multiple times for the same Order. In this case, several posts are created but only the most recent post is published when the Order is completed. I would like to publish all the posts connected to the Order when the Order is completed.
Solution: Forms Commerce is not designed to support more than one post per Order, so custom code is required to make this work. See the example here using the cred_commerce_after_order_completed API:
// publish all posts created when one commerce form is submitted mutliple times in the same order
add_action( 'cred_commerce_after_order_completed', 'publish_all_ordered_posts', 10, 1 );
function publish_all_ordered_posts( $data ) {
// which order was completed?
$order_id = $data['transaction_id'];
// which posts were created in this order?
$all_order_posts = get_post_meta( $order_id, '_cred_post_id');
// loop over all the created posts
if( !is_array( $all_order_posts ) )
return;
foreach( $all_order_posts as $all_order_post ) {
// check the post status
$this_post_status = get_post_status( $all_order_post );
// publish any unpublished posts
if ( $this_post_status != 'publish' ) {
$args = array(
'ID' => $all_order_post,
'post_status' => 'publish'
);
wp_update_post( $args );
}
}
}