Hi Waqar,
We can now connect multipe "vakexperts" to an "introducties" post so that works, HOWEVER,
What query filter should we apply to > "view" > "content selection" > "introducties" to ONLY SHOW the "introducties" posts to "vakexperts" that have been connected to them?
This is the page we created: hidden link.
We tried a lot of filters but none work so far.
Hi,
I've checked the page "Introducties ingelogde gebruiker" and see that it includes a view to show the "Introducties" posts.
However, since this is a regular page and not a single post page for "Introducties" post type or the "vakexperts" post type, I'm not sure which post you'd like to use as a reference, to show the related posts from?
Can you please share some more details about the exact requirement you have in mind from this view?
regards,
Waqar
Waqar,
I am quite unsure if I understand your question.
I'll break down my issue once again below:
The page "Introducties ingelogde gebruiker" includes a view to show the "introducties" posts BUT the page should ONLY SHOW vakexperts the "introducties" posts for which they have been "connected".
Here's an example:
Let's say there are the following introducties (post type "introducties"):
- introductie A.
- introductie B.
- introductie C.
Vakexpert A (post type "vakexperts") has been connected to introductie A and B.
Vakexpert A should ONLY SEE introductie A and B on the page "Introducties ingelogde gebruiker" AND NOT introductie C.
So my question remains: what query filter or specific settings should we apply to achieve the above behavior?
I hope this makes sense to resolve this issue.
Thank you for sharing these details and I now understand what you mean.
Am I correct to assume that each "vakexperts" user will have a single post in the post type "vakexperts" and he/she will be set as the author of that post?
If not how will the currently logged-in user linked to the "vakexperts" post?
Thank you for confirming and I'll need to perform some tests on my website, with a similar setup.
I'll share my findings with you, as soon as this testing completes.
Thank you for your patience.
Thank you for waiting.
During testing on my website, I was able to filter the view for the "introductie" posts, based on the ID of the current user's "vakexpert" post, using the "wpv_filter_query".
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )
Example:
add_filter( 'wpv_filter_query', 'wpv_filter_query_5663_func', 1000 , 3 );
function wpv_filter_query_5663_func( $query_args, $view_settings ) {
// skip if blocks edit screen
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return $query_args;
}
// process if specific view
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 5663) ) {
$current_user_id = get_current_user_id();
if($current_user_id > 0) {
// get current user's "vakexpert" post
$args = array(
'post_type' => 'vakexpert',
'posts_per_page' => 1,
'post_status' => 'publish',
'author' => $current_user_id,
'fields' => 'ids',
);
$posts_array = get_posts( $args );
if(!empty($posts_array)) {
$query_args['toolset_relationships'] = array( 'role' => 'child', 'related_to' => $posts_array[0], 'relationship' => 'vakexpert-introductie' );
}
else
{
// setting the post type to a non-existent post type so that no results are shown
$query_args['post_type'] = 'xyz';
}
}
else
{
// setting the post type to a non-existent post type so that no results are shown
$query_args['post_type'] = 'xyz';
}
}
return $query_args;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
As a result, the logged-in user will see only the "introductie" posts from the view "Introductie ingelogde gebruikers", which are related to a "vakexpert" where he/she is the author.
And if the current user has no related "introductie" posts or if the visitor is not logged-in, no results will be shown.
My issue is resolved now. Thank you Waqar!