Skip Navigation

[Resuelto] Don’t show pagination on parametric search

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I'm using wpv_filter_query_post_process to remove some posts from the results. I would like to hide the pagination when no results remain.

Solution: Use two filters in combination:

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
 
    $target_views = array( 572 ); // Insertar el ID de la view
 
    if ( in_array( $view_id, $target_views ) ) {
 
        // Si existe un filtro
        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;
            add_filter( 'wpv_view_settings', 'ts_modify_rendered_view', 30, 2 );
        }
    }
 
    return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
 
function ts_modify_rendered_view( $view_settings, $view_id ) {
 
        $view_settings['pagination']['type'] = 'disabled';
 
    return $view_settings;
}
This support ticket is created hace 4 años, 11 meses. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Etiquetado: ,

This topic contains 5 respuestas, has 2 mensajes.

Last updated by juanC-8 hace 4 años, 10 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#1252893

Hi,

https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search/

I've followed this thread to default results blank on parametric search and it works perfect!
But I also want to hide by default the pagination controls.

How can I hide it?

Thank you

#1253229
Screen Shot 2019-05-29 at 12.16.42 PM.png

When you insert the pagination controls in the View editor, you have the option "Don't show pagination elements if there is only one page". If you check this option, the controls will be wrapped in a wpv-pagination shortcode. It will be hidden by default if no results are found (or if only one result is found).

#1254873
Sin título.png

Thank you for the reply Christian

I've done what you did but still showing the pagination controls

I've used this code because I don't want to show default results when I open the search view

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
    
    $target_views = array( 572 ); // Insertar el ID de la view 
  
    if ( in_array( $view_id, $target_views ) ) {
    
        // Si existe un filtro
        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;
        }
    }
    
    return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );

Thanks

#1256283

Ah okay I see, the pagination shortcodes are not affected by this custom code. Let me ask my 2nd tier support team for some additional information here. I'll let you know what I find out.

#1259993

Our 2nd tier support team recommends using the wp_view_settings filter in combination with the post process filter, like this:

function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){

    $target_views = array( 572 ); // Insertar el ID de la view

    if ( in_array( $view_id, $target_views ) ) {

        // Si existe un filtro
        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;
            add_filter( 'wpv_view_settings', 'ts_modify_rendered_view', 30, 2 );
        }
    }

    return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );

function ts_modify_rendered_view( $view_settings, $view_id ) {

        $view_settings['pagination']['type'] = 'disabled';

    return $view_settings;
}

Please try this and let me know if the pagination is still displayed.

#1260327

It works! Thank you Christian

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.