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.
Problem: I would like to create a one-to-many relationship between Users and a post type.
Solution: You can either create a proxy post type for Users and relate that proxy post type using Toolset's Post Relationships feature, or you can create a custom usermeta field that stores a reference to the related post by ID.
Problem: I have two address fields, one in a parent post type and one in a child post type. When a new child post is created, I would like to calculate the distance between the two addresses and save that distance in another custom field in the child post type.
Solution: You can use the cred_submit_complete hook to trigger custom code with the shortcode toolset-maps-distance-value to calculate the distance between two addresses. Use the update_post_meta function to store that distance in another custom field.
Problem: I would like to filter the parent post options in a Form that creates child posts. I would like to add custom code that filters the options based on their other post relationships.
Solution: Use the pre_get_posts filter to filter the parent post options in the parent post field. See the following example code:
/**
* Filter the Children parent field in the connect-toy-to-childmale Relationship Form
* to only show Children connected to Gender Male.
* https://toolset.com/forums/topic/filtering-posts-for-relationship-connection-in-a-submission-form/
*/
function filter_parent_posts( $query ){
$parent_post_type = "child"; // slug of parent post type
$child_post_type = "toy"; // slug of child post type
$rel_slug = "gender-child"; // slug of gender-child post relationship
$male_post_id = 9; // ID of Gender Male post
$rel_form_id = 26; // ID of the relationship form
// relationship form is on Toy single posts, queries parent_post_type posts
if ( ( defined('DOING_AJAX') && DOING_AJAX )
&& isset($query->query['post_type'][0])
&& $query->query['post_type'][0] == $parent_post_type
&& isset($_REQUEST['action'])
&& $_REQUEST['action'] == 'cred_association_form_ajax_role_find'
&& isset($_REQUEST['form_id'])
&& $_REQUEST['form_id'] == $rel_form_id
) {
// querying by gender post, which is parent in gender-child
$males = toolset_get_related_posts( $male_post_id, $rel_slug, array(
'query_by_role' => 'parent',
'limit' => 1000,
'offset' => 0,
'args' => array(),
'return' => 'post_id',
'role_to_return' => 'child'
));
$query->set( 'post__in', $males );
}
}
add_action( 'pre_get_posts', 'filter_parent_posts', 101, 1 );