I am trying to block listing all results when no option is selected on the view search form.
On my filter editor, i have the code:
------------
<div class="formulario">
<div>
[wpv-control-postmeta field="wpcf-cidade-do-anuncio-empresa" type="select" default_label="Cidade" url_param="wpv-wpcf-cidade-do-anuncio-empresa"]
</div>
<div>
[wpv-control-postmeta field="wpcf-bairro-do-anuncio-empresa" type="select" default_label="Bairro" url_param="wpv-wpcf-bairro-do-anuncio-empresa"]
</div>
<div>
[wpv-control-postmeta field="wpcf-categoria-empresa" type="select" default_label="Categoria" url_param="wpv-wpcf-categoria-empresa"]
</div>
<div></div>
--------------
I need to check if the user selects an option on wpcf-cidade-do-anuncio-empresa. The other fields are optional. I can´t list all results. I am using this code on functions.php but it isn´t working:
$ids = array(830); //view code
if (in_array($view_id, $ids)){
if ( isset($_GET['wpcf-cidade-do-anuncio-empresa']) && $_GET['wpcf-cidade-do-anuncio-empresa'] != 'Cidade' )
// Cidade is the default value
{
} else {
$query_args['post__in'] = array(0);
}
}
return $query_args;
Can you help me, please?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
Thank you for contacting our support forum.
Could you send the entire code section that you are using to remove the results.
Thanks,
Shane
Hi Shane,
Here is the code:
add_filter( 'wpv_filter_query', 'default_blank_func', 10, 3 );
function default_blank_func( $query_args, $view_settings, $view_id ) {
$ids = array(830); //view code
if (in_array($view_id, $ids)){
if ( isset($_GET['wpcf-cidade-do-anuncio-empresa']) && $_GET['wpcf-cidade-do-anuncio-empresa'] != 'Cidade' )
// Cidade is the default value
{
} else {
$query_args['post__in'] = array(0);
}
}
return $query_args;
}
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
Thank you for the code.
Would you mind providing me with access to the site and a link to the page with this view so that I can help better with resolving this.
The private fields have been enabled for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
Thank you for the credentials, however it seems that the password is incorrect.
Could you check on this and let me know.
Thanks,
Shane
Sorry, can i give you the password on a secure form?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
I've enabled the private fields once more.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
I must apologize for the delay in response.
I'm currently having a look at this for you now.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Selmo,
I've managed to resolve this for you and it should now be working.
Thanks,
Shane
Shane,
It is working great!
Thank you very much,
Selmo