CRED plugin allows you to build forms that create child posts and set parents for these posts, supporting the parent-child relationship functionality from Types plugin.
When you ask for help or report issues, make sure to tell us the structure of your content and the relationship between the content types.
Viewing 15 topics - 556 through 570 (of 600 total)
Problem: I would like to establish relationships between two posts in a New Post Form.
Solution: It's not currently possible to manage M2M relationships in a Post Form, you must create a Relationship Form. To predefine the values, you can use the parent_item and child_item shortcode attributes in the cred_relationship_form shortcode:
Problem: I would like to add a new checkbox to an existing CRED Form, but the value is not saved.
Solution: First, add the checkbox field to an existing Field Group in wp-admin. Then edit the Form. Use the "Add Post Fields" button to insert the new field in the Form.
Problem: I have a Form that creates child posts. I would like to use the cred_form_validate API to ensure that the parent post chosen in the Form has specific terms and custom field values.
Solution: Use custom code to query the parent post and compare its terms and custom field values.
add_filter('cred_form_validate','validate_parent_consultant',10,2);
function validate_parent_consultant($field_data, $form_data)
{
list($fields,$errors)=$field_data;
//error_log(print_r($fields, true));
$forms = array( 6 );
// validate if correct CRED form ID
if ( in_array( $form_data['id'], $forms ) ) {
// edit these 6 lines as needed
$parent_field_post_name = '@consultant-event_parent';
$parent_field_name = '@consultant-event.parent';
$checkbox_slug = 'parent-checkbox-field';
$taxonomy_slug = 'consultant-taxonomy';
$taxonomy_terms = array('a', 'b');
$test_cbs = array( 'a', 'b', 'c' );
// get the parent ID from the form field
$parent_id = $_POST[$parent_field_post_name];
// check if parent has all matching checkboxes
$vals = types_render_field($checkbox_slug, array( "separator"=>",", "id"=>$parent_id));
$any = strlen($vals) > 0 ? explode(',', $vals) : array();
$cbs_match = sizeof($any) > 0 && sizeof(array_intersect( $any, $test_cbs)) == sizeof($test_cbs);
// Test if the parent has all the right term(s)
$matching_terms = [];
foreach($taxonomy_terms as $tax_term) {
if( is_object_in_term( $parent_id, $taxonomy_slug, $tax_term ) ){
$matching_terms[]= $tax_term;
}
}
$terms_match = sizeof($matching_terms) == sizeof($taxonomy_terms);
// combine parent validations
if( !$cbs_match || !$terms_match ) {
$errors[$parent_field_name] = __('Select a different parent post.', 'your-theme-domain');
}
}
//return result
return array($fields,$errors);
}
Problem: I have several custom fields associated with a M2M relationship intermediary post, and a Relationship Form that allows Users to create these relationships on the front-end. When WPML is active, the custom field values are not saved when I submit the Relationship Form.
Solution: Update to the latest version of Toolset plugins.