Home › Toolset Professional Support › [Resolved] Make View Search Field Optional
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
Hello,
I currently had to recreate my site, dailydrivenms.com, due to a plugin issue. I'm trying to get a search view functioning again.
I currently have 4 custom post types:
Makes
Models
Platforms
Tuners
These are connected by 3 relationships:
A one-to-many between Makes and Models
A one-to-many between Models and Platforms
A many to many between Platforms and Tuners
There is also a custom field called Tuning Categories. it's a checkboxes field with 6 options, and you can select one or all of them:
-Brakes
-Drivetrain
-Exterior
-Interior
-Power
-Suspension
I set up the view based on the many-to-many post relationship between Platforms and Tuners. it is located at hidden link. It searches the Make, Model, and Platform just fine. It even searches by the category just fine. However, it seems a category is required in order to complete the search. If I set the default value to "All", it will not pull up any search results as "all" is not one of the options. If I set it as blank, it defaults to the first option, Brakes, which limits the first search results.
What I want to see happen is the Tuning Categories be an optional field that shows either a blank entry or "Optional" as the default and to show all search results based on the first 3 fields. I've attached screenshots of my setup, as below is the custom code I use on the form to remove duplicates. Thank you in advance.
<?php
/**
* Modify output of View "Tuner Search"
*
* 1. no initial results until a filter is applied
* 2. avoid duplicates
* 3. promote featured results to the top
*/
add_filter('wpv_filter_query_post_process', 'remove_duplicates_query', 101, 3);
function remove_duplicates_query($query_results, $view_settings, $view_id)
{
$viewid = 1524;
$relationship_slug = 'platform-tuner';
if ( $view_id != $viewid )
return $query_results;
// has a filter been applied?
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
return $query_results;
}
// iterate over results to remove duplicates and to promote featured
$tuners = [];
$featured = [];
$posts = $query_results->posts;
foreach ($posts as $key => $post) {
$tuner_ids = toolset_get_related_posts(
$post->ID,
$relationship_slug,
[
'query_by_role' => 'intermediary',
'role_to_return' => 'child',
'return' => 'post_id'
]
);
$tuner_id = $tuner_ids[0];
if ( in_array( $tuner_id, $tuners ) ) {
// duplicate, discard
unset( $query_results->posts[$key] );
$query_results->post_count --;
$query_results->found_posts --;
} else {
$tuners[] = $tuner_id;
// unique (so far), is it featured?
$is_featured = get_post_meta($tuner_id, 'wpcf-featured', true);
if ( $is_featured ){
$featured[] = $post;
// remove from array of results, to be added back later at the top
unset( $query_results->posts[$key] );
}
}
}
// any featured to add back at top?
if ( $featured ){
$posts = array_merge( $featured, $query_results->posts );
$query_results->posts = $posts;
} else {
$posts = array_values( $query_results->posts );
$query_results->posts = $posts;
}
return $query_results;
}
Hello. Thank you for contacting the Toolset support.
You should add a placeholder "Please Select" with your taxonomy select filter. I see you already have that in screenshot but I wonder why its not working on frontend.
Can you please share problem URL where you added the view as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
When I try to access the wp-admin once I provide username and password - it shows "Access Blocked" message.
Can you please confirm how should I able to login to admin panel?
I've replaced the password again. Try now please.
On this page: hidden link
When I input the shared user/pass details it shows me blank white page with message "Access Blocked". Can you please remove all the blockages or security plugins for now so I can access your site. If you have country wise IP block then you can remove that as well.
Hopefully you're using wp-admin as wp-login is blocked. The full url is hidden link.
I turned off the security plugin. Please try again.
Actually - when I try wp-admin it shows the following screen as you can see with the following screenshot:
- hidden link
I do not find normal login button for the login form.
Can you please tell me how can I login to wp-admin?
That’s the correct login. I’ve tested the username and password and it works for me. What error are you seeing?
I'm getting the following error as you can see with the following screenshot when I try to login to wp-admin using the access details you shared with us:
=> hidden link
alright, I've changed some settings. try it now.
Still I can see the same result - I'm not able to login yet.
I do not see normal login button to submit the login details on wp-admin page.
The login page you’ve showed is the only one I’ve ever had and I’ve been helped multiple times by other developers. I have never seen a “normal” login button I can’t help you with that.
I have completely disabled the stop spammers plugin. Please try it now
Hi,
Minesh was having difficulty in accessing the website's admin area, so I'll be following up on this ticket.
( I can access the admin area, just fine )
I'm currently reviewing the website's set up and will be performing some tests on a test website. Will share the findings, as soon as this testing completes.
Thank you for your patience.
regards,
Waqar
Thank you for waiting.
During troubleshooting, I noticed that the custom function that was limiting the results, before the filters were applied, needed some adjustment.
I've replaced this line:
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
With this new line:
if( empty($_GET['wpv-relationship-filter-make']) || empty($_GET['wpv-relationship-filter-model']) || empty($_GET['wpv-relationship-filter']) ) {
And the results are now showing even when the 'Tuning Categories' field value is not selected.
That looks like it worked for that field. However, before rebuilding the site, I used to be able to select any of the below combinations and still get results. For example:
Selecting no options gave me all of the tuners
Selecting Nissan in the make field gave me every tuner that carried Nissan parts
Selecting Nissan in the make field would give me all of the Nissan models, and then once I selected a model (Skyline for example), I would get all of the Tuners that supplied parts for that model.
And finally, I can select the whole car (Make + Model + Platform) and get all Tuners that supply parts for that specific Platform
Is there a way to reprogram it that way again? I do still want the optional Categories box.
Thanks in advance.