I am creating a portal for different counties where each county will have several different users. Each user in that county should be able to view invoices(post type) created by any user within that county. Other county users should not be able to view other counties invoices(post type). To do that i have one custom post type that has all the counties in the database. To which i can attach to individual users and invoices(post type). 4 - 5 users will have same counties thru out the database.
Solution:
There isn't exact same feature within Toolset plugins, as a workaround, please check the details here:
Problem: I have two post types in a many-to-many (M2M) post relationship. I would like to show a View of one of these post types, and apply a filter so that only posts that have no assigned relationship are shown.
Solution:
You can use the wpv_filter_query API along with the toolset_get_related_posts API to apply a custom Query Filter.
/**
* Apply a custom filter to only show Projects which are not yet related to any Client (M2M relationship).
* This filter is currently used on the Single Company page.
*/
add_filter('wpv_filter_query', 'ts_not_linked_to_client_filter', 10, 3);
function ts_not_linked_to_client_filter($query, $view_settings, $view_id) {
$views = array( 64 ); // only filter these views
if( in_array( $view_id, $views ) ) {
$project_ids = array(); // push all related project IDs here
$client_args = array(
'post_type' => 'client',
'posts_per_page' => -1,
);
$clients = new WP_Query($client_args); // get all clients
foreach ($clients->posts as $client ) {
$projects = toolset_get_related_posts(
$client->ID,
'client-project',
'parent',
1000000,
0,
null,
'post_id',
'child'
);
$project_ids = array_merge($project_ids, $projects); // push the related project IDs into this array
}
$query['post__not_in'] = isset( $query['post__not_in'] ) ? $query['post__not_in'] : array();
$query['post__not_in'] = array_merge($query['post__not_in'], $project_ids ); // update the main query to exclude related project ids
}
return $query;
}
Say I have a Many to Many Relationship that links CPTs People and Cities. There is a Post Relationship Field called Type (checkboxes) which specifies the person's connection to the City. (Born, Lived, Current)
Is there any way I can restrict it so that only one City can be connected as Born and Current, whereas many can be connected for Lived?
Solution:
You can setup two one-to-many relationships between post type "City" and "People":
- Born
- Current
Then when your user edit a single "People" post, he can:
- related only one "City" post in relationship "Born"
- related only one "City" post in relationship "Current"
Display a list of custom post type States sharing a parent custom post type State Group. The relationship, states-in-group, is one State Group to many States.
Solution:
Need to fix the post type relationship slug in Views shortcode, see details here: