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 a custom post type and a repeatable field group (RFG) in that custom post type. I would like to create a list of all the custom posts and in that list show a list of the RFGs associated with that post.
Solution: This requires a nested View structure. Since it is not possible to create a nested View in Blocks, you must use the legacy Views editor. The process is outlined in another ticket.
Problem: I would like to display a View of related posts in an M2M relationship. There is checkbox in the intermediary post type (in the relationship) and I would like to display only those related posts where the checkbox is unchecked.
Solution: This requires some custom code, and it also requires that the View is configured to display the intermediary post type. Add the following code snippet to filter by an unchecked checkbox:
add_filter( 'wpv_filter_query', 'unchecked_ints',99,3 );
function unchecked_ints( $query_args,$views_settings, $view_id) {
global $post;
$field_slug = 'release-artist-checked';
$views = array( 48324 ); /* "Collaborations" */
$ints_args = array(
'query_by_role' => 'child',
'role_to_return' => 'intermediary',
'limit' => 1000,
'offset' => 0,
'args' => [
'meta_key' => 'wpcf-' . $field_slug,
'meta_value' => 1,
'meta_compare' => '='
]
);
$ints = toolset_get_related_posts( $post->ID, 'supporting-artists', $ints_args);
// you should not need to edit below this line
if ( in_array( $view_id, $views ) ){
$query_args['post__not_in'] = $ints;
}
return $query_args;
}
Problem: I would like to know if it is better to include User data in User fields in the User profile, or to create a proxy post type as explained in the documentation for post relationships and custom search for Users?
Solution: There are pros and cons for each approach. If you plan to use custom search Views to search for Users based on filtering by these custom fields, or if you plan to use Repeatable Field Groups for some of these fields, or if you plan to use post relationships to connect multiple Users to the same post, a proxy post type is probably required as explained in the documentation link below.
Problem: I would like to display the title of the post selected in a post reference field using PHP, but when I output the value of types_render_field I get a number.
Solution: This number is the referenced post ID. You can use it to get the post title with the WordPress function get_the_title:
Problem:
Count number of entries in repeating field group return 0
Solution:
To get total count based on repeating field group items, you will require to use the post relationship API function toolset_get_related_posts().