Types plugin lets you easily create relationships between different post types and connect them using GUI controls. You can also connect multiple post types and build many-to-many post relationships.
When you ask for help or report issues, make sure to tell us what you have created so far and the structure that you want to achieve.
Viewing 15 topics - 166 through 180 (of 378 total)
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: