|
Testing the value of checkbox in intermediate post for many-to-many relationship
Started by: Anthony
in: Toolset Professional Support
Quick solution available
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;
}
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
|
|
2 |
13 |
3 years, 5 months ago
Anthony
|
|
user data: proxy post or user data fields?
Started by: joostH-2
in: Toolset Professional Support
Quick solution available
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.
Relevant Documentation:
https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/
|
|
2 |
5 |
3 years, 5 months ago
joostH-2
|
|
I need to show the Title of a Post Reference Type field using PHP
Started by: alexanderS-9
in: Toolset Professional Support
Quick solution available
|
|
2 |
3 |
3 years, 5 months ago
alexanderS-9
|
|
Count number of entries in repeating field group return 0
Started by: stephaneL-3
in: Toolset Professional Support
Quick solution available
|
|
2 |
7 |
3 years, 6 months ago
stephaneL-3
|