Yesterday we moved to a new host, and also installed the latest Toolset plugins (I think it was Blocks and Maps), so not sure which could be an issue.
We have a normal Toolset search page, which was all working fine on the old host and before the latest plugin update: hidden link
Currently the 1st page of results is either blank or only showing very recent results (ie nannies who recently registered with us). We have no such restriction on the query. The first page should show 10 results, but currently only showing 2 results. This morning page 1 showed no results, but results continued on page 2.
It looks like a caching issue for me, however have set the page to not be cached by WP Rocket, and also disabled the Redis cache plugin.
After disabling caching on the page, I cleared the WP Rocket Cache just to be sure and "flushed" the Redis cache.
Edit the View → in Pagination & Settings, temporarily disable “Cache results of this View” (if enabled), save, retest.
Pagination parameter clash
If the View uses the default URL parameter page, it can conflict with the WordPress page’s own pagination variable—especially on multilingual URLs—so page 1 may behave oddly.
Fix (Legacy Views):
View → Pagination and Slug → change the “Pagination page parameter” from page to something unique, e.g. nnpg.
Fix (Blocks View):
Select the View block → Pagination panel → URL parameter name → set nnpg.
Update the page, retest page 1.
Recreate the View
Create a new view and do not copy anything from the old view and use normal setup guides and see if it fixes the issue.
I think I've ascertained what is actually happening. The items in the View Search Nanny Ads from CPT nanny-ad.
When these Nanny Ads are created (on the front end by users), they have a Boolean flag on the field nanny-visible-for-families set to 0 by default, as the Nanny User that created them has not yet been verified.
When the User has been verified, my colleague changes the user's role from 'unverified_nanny' to 'native_nanny' (ie a fully qualified, verified nanny). Also she updates the field nanny-visible-for-families from 0 to 1 in the Nanny Ad, so that it would appear in the View "Find a Native Nanny Search and Results View".
Yesterday, as she verified the nannies and updated the nanny-ad fields from 0 to 1, the ads began to appear in the search.
Ideally, we would like a cleaner solution where the we could filter the View "Find a Native Nanny Search and Results View" by post author's role, so that the View could only show Nanny Ads (CPT nanny-ad) from users with role 'native_nanny'. We still need to retain the Boolean flag field nanny-visible-for-families so that Nannies can choose whether to hide their ads or not.
When I add a filter and choose post author, I cannot see a way to filter on the author's role. I checked here too:
First of all sorry for the late reply.
It seems to be hard to do this only via UI. I did not try this method, but I thought, what if you add an author-role filter via a small hook.
Try the code below using the Toolset custom code UI:
add_filter( 'wpv_filter_query', function( $query_args, $view_settings, $view_id ) {
// Target by View slug (preferred) OR by numeric ID.
$target_view_slugs = array( 'find-a-native-nanny-view' ); // <-- replace with your View's slug
$is_target = ( isset( $view_settings['view_slug'] ) && in_array( $view_settings['view_slug'], $target_view_slugs, true ) )
|| (int) $view_id === 0; // optionally replace 0 with your View ID
if ( ! $is_target ) {
return $query_args;
}
// Get all user IDs that have the role `native_nanny`.
$author_ids = get_users( array(
'role' => 'native_nanny',
'fields' => 'ID',
) );
// If no authors match, force an empty result in a cheap way.
if ( empty( $author_ids ) ) {
$query_args['post__in'] = array( 0 );
return $query_args;
}
// Constrain the View to those authors.
$query_args['author__in'] = $author_ids;
return $query_args;
}, 10, 3 );
Keep your existing meta filter nanny-visible-for-families = 1 in the View. The hook simply adds author__in on top.
If you also want to include another role later (e.g., premium_nanny), change to:
I was kind holding back here too becuase I don't want to come into conflict with any changes you might be making from the other ticket. The other ticket has much higher priority because Location is the most important search critieria for our users.
Is it possible to set this ticket so it doesn't auto-close until the other ticket you're working on is resolved?
Using Christopher's suggested code as a template I added the Custom Code snippet:
filter-find-a-native-nanny-view-by-postauthor.php
All I changed was the View slug, and changed 'role' => 'native_nanny' to 'role__in' => ['native_nanny']
On querying the view, (Find a Native Nanny Search and Results View), initially I had 11 results, as expected, 10 from nanny Siobhan and 1 from nanny Sabine.
When I change nanny Siobahn (nativenanny2@hotmail.com) to role "Unverified Nanny" (unverified_nanny) and requery, I'm getting zero results. But when I set her role back to "Native Nanny" (native_nanny), I get 11 results, 10 from her, and 1 from Sabine (nativenanny4@gmail.com).
I would expect to see the Nanny Ad from Sabine, even when Siobhan is set to role unverified_nanny.
So I don't think the query filter is working correctly...
What if you change the role__in argument to as follows to search in two roles "native_nanny" and "unverified_nanny" and save your code snippet and check if that help you to get the correct results.