Inicio › Toolset Professional Support › [Resuelto] Hide results from a search before user search but not show "no items" message
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Etiquetado: Custom search, Plugin Views
Documentación relacionada:
Este tema contiene 9 respuestas, tiene 2 mensajes.
Última actualización por Jaime hace 4 años, 10 meses.
Asistido por: Nigel.
Tell us what you are trying to do?
I would like to hide the results from a search until user click on "search" button. ( I've alerady reach this point) BUT i would need also to not show the "no items" message.
I mean:
1) When a user see the search form no results are displayed.
2) User makes a search -> Results are displayed
3) If no results are available -> Message of "no results" is displayed
What I have now:
1) When a user see the search form no results are displayed BUT message of "no result" is also displayed
Is there any documentation that you are following?
Yes I used this code from another ticket support and it's working so far.
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array( 1980 ); // Comma-separated list of View IDs
if ( in_array( $view_id, $target_views ) ) {
// if there is a search term set
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;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
There is actually a simpler solution that doesn't require any custom code, which I suggest you remove.
It relies on the fact that whenever a user performs a search some URL parameters are added with details of the search, and the parameter wpv_view_count is always included, so we can test for the presence of that parameter and if it is absent conclude that this is the initial visit to the page before any search has been conducted.
So we wrap the entire loop output in a conditional shortcode, like so:
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> [wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"] <wpv-loop> <h3>[wpv-post-link]</h3> </wpv-loop> [/wpv-conditional] <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
Do you want to try that and let me know how you get on?
Hi Nigel.
Thanks for your answer.
I'm sorry, but I inserted your code, and deleted the previous custom code, but the result is the same: the form displays the default results.
What I have right now is this
Anything wrong?
Thanks a lot Nigel!
[wpv-layout-start] [wpv-items-found] <div class="container"> <div class="col-sm-8"></div> <div class="col-sm-4"> <div class="panel panel-default panel-select"> <div class="panel panel-body "> <center> <h6>[wpml-string context="wpv-views"]Ordenar por - [/wpml-string] [wpv-sort-orderby type="select" options="post_title,post_date,field-provincia-guia-produccion" label_for_post_title="Nombre" label_for_post_date="Más recientes" label_for_field-provincia-guia-produccion="Provincia" orderby_ascending_for="post_title,post_date,field-provincia-guia-produccion"]</h6></center> </div> </div> </div> </div> <br> <!-- wpv-loop-start --> [wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"] <wpv-loop> <div class="container"> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title" data-toggle="collapse" href="#collapse-[wpv-post-id]" aria-expanded="false" aria-controls="collapse-[wpv-post-id]" style="color:white"> [wpv-post-title]<span class="panel-title pull-right label-panel hidden-xs">[types field='provincia-guia-produccion'][/types]</span></h3> </div> <div class="collapse" id="collapse-[wpv-post-id]"> <div class="panel-body"> <!-- el contenido del body se inserta aquí, no en la plantilla!!! --> <div class="row"> <div class="panel panel-ficha"> <center> <h3> [types field='persona-de-contacto-guia-produccion'][/types]</h3> <h5> <span class="label label-profesional">[types field='tipo-de-empresa'][/types]</span> </h5> <h5> <span class="label label-categoria">[wpv-post-taxonomy type="categoria-guia-produccion" format="name" separator="</span> <span class='label label-categoria'>"]</span> </h5> <hr> [types field='ubicacion-guia-produccion'][/types]<br> [types field='poblacion-guia-produccion'][/types] ([types field='provincia-guia-produccion'][/types])<br> [types field='telefono-guia-produccion'][/types]<br> [types field='email-guia-produccion'][/types]<br> [types field='web-guia-produccion'][/types] </center> <div class="row"> <div class="col-md-12 col-rrss"> <center> [wpv-conditional if="( NOT(empty($(wpcf-facebook-guiaprod))) )"]<a href="[types field='facebook-guiaprod' output='raw' target="_blank"][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-facebook-square"></i></span> </a>[/wpv-conditional] [wpv-conditional if="( NOT(empty($(wpcf-twitter-guiaprod))) )"]<a href="[types field='twitter-guiaprod' output='raw'][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-twitter-square"></i></span> </a>[/wpv-conditional] [wpv-conditional if="( NOT(empty($(wpcf-instagram-guiaprod))) )"]<a href="[types field='instagram-guiaprod' output='raw' target="_blank"][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-instagram"></i></span></a>[/wpv-conditional] [wpv-conditional if="( NOT(empty($(wpcf-youtube-guiaprod))) )"]<a href="[types field='youtube-guiaprod' output='raw' target="_blank"][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-youtube"></i></span></a>[/wpv-conditional] [wpv-conditional if="( NOT(empty($(wpcf-vimeo-guiaprod))) )"]<a href="[types field='vimeo-guiaprod' output='raw' target="_blank"][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-vimeo"></i></span></a>[/wpv-conditional] [wpv-conditional if="( NOT(empty($(wpcf-linkedin-guiaprod))) )"]<a href="[types field='linkedin-guiaprod' output='raw' target="_blank"][/types]"><span style="font-size: 30px; color: Dodgerblue;"> <i class="fab fa-linkedin"></i></span></a>[/wpv-conditional] </center> </div> </div> </div> </div> <div class="row"> <hr> <div class="row-view"> <div class="col-sm-12"> [wpv-view name="listado-trabajos-guia-produccion-vista-para-visitantes-listado-horizontal"] </div> </div> </div> <!-- llega hasta aquí --> </div> </div> </div> </div> <br> </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] <div class="pagination">[wpv-pager-nav-links output="bootstrap"]</div> [wpv-layout-end] <br> [wpv-no-items-found] <strong>[wpml-string context="wpv-views"]<center>Lo sentimos, no hemos encontrado ninguna empresa con las características que buscas.<br> Estamos actualizando la base de datos de la Guía de producción, por lo que te recomendamos que nos escribas a info@andaluciafilm.com y estaremos encantados de ayudarte a encontrar la empresa que buscas.</center>[/wpml-string]</strong> [/wpv-no-items-found]
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
It might not be obvious because you already have quite a few conditional shortcodes, but it looks to me like you didn't close the wpv-conditional shortcode from my example which you inserted right at the start of the wpv-loop.
Hi again Nigel.
You were right. Sorry for that.
I missed that closure.
Now, it dosen't show any result (not before triggering the search, nor after trigerring the search).
You can see the search form in action here, just in case it's easier for you to solve the problem.
enlace oculto
Besides I found this situation, but I don't understand why (maybe you do).
If I click on the pagination items, before triggering the search, it shows all the results.( I can see on the url the "wpv_view_count" that you added on the link info below the screen, but I cannot see it on the url when I trigger the search).
What I have now is this:
[wpv-layout-start]
[wpv-items-found]
<div class="container">
<div class="col-sm-8"></div>
<div class="col-sm-4">
<div class="panel panel-default panel-select">
<div class="panel panel-body ">
<center> <h6>[wpml-string context="wpv-views"]Ordenar por - [/wpml-string] [wpv-sort-orderby type="select" options="post_title,post_date,field-provincia-guia-produccion" label_for_post_title="Nombre" label_for_post_date="Más recientes" label_for_field-provincia-guia-produccion="Provincia" orderby_ascending_for="post_title,post_date,field-provincia-guia-produccion"]</h6></center>
</div>
</div>
</div>
</div>
<br>
<!-- wpv-loop-start -->
[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
<wpv-loop>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title" data-toggle="collapse" href="#collapse-[wpv-post-id]" aria-expanded="false" aria-controls="collapse-[wpv-post-id]" style="color:white">
[wpv-post-title]<span class="panel-title pull-right label-panel hidden-xs">[types field='provincia-guia-produccion'][/types]</span></h3> </div>
<div class="collapse" id="collapse-[wpv-post-id]">
<div class="panel-body">
<!-- el contenido del body se inserta aquí, no en la plantilla!!! -->
<div class="row">
<div class="panel panel-ficha">
<center>
<h3> [types field='persona-de-contacto-guia-produccion'][/types]</h3>
<h5> <span class="label label-profesional">[types field='tipo-de-empresa'][/types]</span> </h5>
<h5> <span class="label label-categoria">[wpv-post-taxonomy type="categoria-guia-produccion" format="name" separator="</span> <span class='label label-categoria'>"]</span> </h5>
<hr>
[types field='ubicacion-guia-produccion'][/types]<br>
[types field='poblacion-guia-produccion'][/types] ([types field='provincia-guia-produccion'][/types])<br>
[types field='telefono-guia-produccion'][/types]<br>
[types field='email-guia-produccion'][/types]<br>
[types field='web-guia-produccion'][/types]
</center>
<div class="row">
<div class="col-md-12 col-rrss">
<center>
[wpv-conditional if="( NOT(empty($(wpcf-facebook-guiaprod))) )"]
</span>
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($(wpcf-twitter-guiaprod))) )"]
</span>
[/wpv-conditional]
[wpv-conditional if="( NOT(empty($(wpcf-instagram-guiaprod))) )"]
</span>[/wpv-conditional]
[wpv-conditional if="( NOT(empty($(wpcf-youtube-guiaprod))) )"]
</span>[/wpv-conditional]
[wpv-conditional if="( NOT(empty($(wpcf-vimeo-guiaprod))) )"]
</span>[/wpv-conditional]
[wpv-conditional if="( NOT(empty($(wpcf-linkedin-guiaprod))) )"]
</span>[/wpv-conditional]
</center>
</div>
</div>
</div>
</div>
<div class="row">
<hr>
<div class="row-view">
<div class="col-sm-12">
[wpv-view name="listado-trabajos-guia-produccion-vista-para-visitantes-listado-horizontal"]
</div>
</div>
</div>
<!-- llega hasta aquí -->
</div>
</div>
</div>
</div>
<br>
</wpv-loop>
[/wpv-conditional]
<!-- wpv-loop-end -->
[/wpv-items-found]
<div class="pagination">[wpv-pager-nav-links output="bootstrap"]</div>
[wpv-layout-end]
<br>
[wpv-no-items-found]
[wpml-string context="wpv-views"]<center>Lo sentimos, no hemos encontrado ninguna empresa con las características que buscas.<br> Estamos actualizando la base de datos de la Guía de producción, por lo que te recomendamos que nos escribas a info@andaluciafilm.com y estaremos encantados de ayudarte a encontrar la empresa que buscas.</center>[/wpml-string]
[/wpv-no-items-found]
-> If it's easier for you I can provide you admin credentials to test on my developing site. Just let me know.
Thanks a lot Nigel!
🙂
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
That's odd, the wpv_view_count parameter is normally added, but never mind, you can choose another parameter which occurs both with pagination or search instead, e.g. wpv_post_search
So replace wpv_view_count with wpv_post_search in the conditional shortcode.
You would likely want to wrap the pagination controls in the same shortcode so that they are only displayed after an initial search.
Thanks again for your answer Nigel.
I tried this before, wondering if I insert any field related with the search it should work.
But it doesn't.
🙁
The behaviour is exactly the same with wpv_post_search than it was with wpv_view_count
(now I have it with wpv_post_search, if you want to check it out)
I noticed something odd too.
If I make a search with no results (for example 'Categoria profesional > Arte' ) it seems to work fine, because it gives me the "no items" message. But if I search something with results (for example 'Categoría profesional > Diseño grafico') it dosen't give me the results, nor the "no items" message.
Does it make any sense for you?
Any clue?
Thanks again Nigel.
(if it is easier for you to have a look, I can give you credentials to access)
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
I best take a look at your site, if I can get credentials from you please.
I've set up a private reply.
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
I tried using the wpv_sort_orderby parameter instead, and now it seems to work as intended when I tested.
Could you please verify?
My issue is resolved now.
Nigel is great!
🙂