Edit Query Arguments and Pagination Problem

Forums › Forums › Search & Filter Pro › Edit Query Arguments and Pagination Problem

Viewing 10 posts – 1 through 10 (of 15 total)
  • Anonymous
    #118701

    Hello!

    I have a custom page template which has the following args to WP_Query:

    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $args = array(
      'post_type'=> 'tarefa',
      'posts_per_page' => 5,
      'order' => 'DESC',
      'author' => $feed_rc,
      'meta_query' => $feed_cd,
      'paged' => $paged,
    );
    $args['search_filter_id'] = 2817;
    $wp_query = new WP_Query( $args );
    

    The problem was it was ignoring my meta_query, showing values from all posts on the filter.

    To solve this, I used the “Edit Query Arguments” filter:

    
    function filter_function_name( $args, $sfid ) {
    
    if ( $sfid == 2817 ) {
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    
    $args = array(
      'post_type' => 'tarefa',
      'posts_per_page' => 5,
      'order' => 'DESC',
      'author' => $feed_rc,
      'meta_query' => $feed_cd,
      'paged' => $paged,
    );
    
    }
    
      return $args;
    
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    And on my custom page template I used only: $args['search_filter_id'] = 2817;

    Well, the filter is recognizing my meta_query and working perfectly now.

    The question:
    Pagination stopped working.
    When I click on 2nd page link, for exemple, it shows that it’s on 2nd page but actually it loads 1st page results. Using AJAX ou not, it doesn’t work.
    Am I doing the right way or is there another way to achieve that?

    Thanks in advance.

    Trevor
    #118864

    The first way was right, and I assume that DID have pagination.

    You say the 'meta_query' => $feed_cd, is ignored though (likely overridden by our query)?

    What is in that meta query?

    Anonymous
    #119108

    I will try to say step by step what I did =)

    1) The pagination works fine without using Search & Filter Pro.

    2) When I put the $args['search_filter_id'] = 2817; with the other $args, like the first way I posted here, I realized that it ignores meta_query and all the other $args. It uses only the plugin admin config (post_type, posts_per_page, etc…). And pagination works, but without considering all $args written on my custom page.

    3) So I used “Edit Query Arguments” filter to put my $args. Now it is loading my $args, filtering is working great, but pagination loads only 1st page content. When I click on 2nd or 3rd page, it loads 1st page. It seems that everytime I click on page links, it runs the filter from the beginning and shows only page 1 content… I’m not sure… I also tryed changing to infinite scroll mode, but when it loads content it repeats the page 1 content.

    As you’ve requested, I will paste the 'meta_query' => $feed_cd, below. It’s a bit complex, but works fine.

    Thanks!

    <?php
    
    global $current_user;
    
    //FEED GD2 E GD4
    
    if ( current_user_can( 'designer_gd2_gd4' ) ) {
    
      $feed_cd =
    
          array(
    
              'relation'		=> 'AND',
    
              // AREA
              array(
                'key' => 'area_divulgacao_tarefa',
                'value' => array(
                  'educacao',
                  'gestao-negocios',
                  'meio-ambiente',
                  'saude-bem-estar',
                  'sst',
                  'tecnologia-informacao',
                ),
                'compare' 	=> 'IN',
              ),
    
              array(
    
                    'relation'		=> 'OR',
    
                    // MODALIDADE
                    array(
                      'key'		=> 'modalidade_curso',
                      'value'		=> array(
                        'curso-livre',
                        'extensao',
                        //'curso-tecnico',
                        //'pos',
                        //'vestibular',
                        //'gratuidade',
                        //'aprendizagem',
                      ),
                      'compare'	=> 'IN',
                    ),
    
                    //FINALIDADE
                    array(
                      'key'		=> 'finalidade',
                      'value'		=> array(
                        //'dcurso',
                        'devento',
                        'outrafinalidade',
                      ),
                      'compare'	=> 'IN',
                    ),
              ),
        );
    
    }
    
    //FEED GD1 E GD3
    
    if ( current_user_can( 'designer_gd1_gd3' ) ) {
    
      $feed_cd =
    
          array(
    
              'relation'		=> 'AND',
    
              // AREA
              array(
                'key' => 'area_divulgacao_tarefa',
                'value' => array(
                  'arquitetura-urbanismo',
                  'comunicacao-artes',
                  'desenvolvimento-social',
                  'design',
                  'eventos-lazer',
                  'gastronomia',
                  'hotelaria-turismo',
                  'limpeza-conservacao-zeladoria',
                  'moda',
                ),
                'compare' 	=> 'IN',
              ),
    
              array(
    
                    'relation'		=> 'OR',
    
                    // MODALIDADE
                    array(
                      'key'		=> 'modalidade_curso',
                      'value'		=> array(
                        'curso-livre',
                        'extensao',
                        //'curso-tecnico',
                        //'pos',
                        //'vestibular',
                        //'gratuidade',
                        //'aprendizagem',
                      ),
                      'compare'	=> 'IN',
                    ),
    
                    //FINALIDADE
                    array(
                      'key'		=> 'finalidade',
                      'value'		=> array(
                        //'dcurso',
                        'devento',
                        'outrafinalidade',
                      ),
                      'compare'	=> 'IN',
                    ),
              ),
        );
    
    }
    
    //FEED INSTITUCIONAL
    
    if ( current_user_can( 'designer_institucional' ) ) {
    
      $feed_cd =
    
          array(
    
              'relation'		=> 'OR',
    
              // MODALIDADE
              array(
                'key'		=> 'modalidade_curso',
                'value'		=> array(
                  // 'curso-livre',
                  // 'extensao',
                  'curso-tecnico',
                  'pos',
                  'vestibular',
                  'gratuidade',
                  'aprendizagem',
                ),
                'compare'	=> 'IN',
              ),
    
              array(
    
                    'relation'		=> 'AND',
    
                    // AREA
                    array(
                      'key' => 'area_divulgacao_tarefa',
                      'value' => array(
                        'idiomas',
                        'gerencias',
                        'campanhas',
                        'editora',
                        'hoteis',
                      ),
                      'compare' 	=> 'IN',
                    ),
    
                    //FINALIDADE
                    array(
                      'key'		=> 'finalidade',
                      'value'		=> array(
                        'dcurso',
                        'devento',
                        'outrafinalidade',
                      ),
                      'compare'	=> 'IN',
                    ),
              ),
        );
    
    }
    
    //FEED PORTAL
    
    if ( current_user_can( 'portal' ) ) {
    
      $feed_cd =
    
          // PUBLICACAO
          array(
            'key'		=> 'publicacao_pecas',
            'value'		=> '"publicacao"',
            'compare' => 'LIKE'
          );
    
    }
    
    // FEED REPRESENTANTES
    
    if ( current_user_can( 'senac' ) ) {
    
      $feed_rc = $current_user->ID;
    
    };
    
    ?>
    
    Trevor
    #119112

    I agree, a bit complex for me, but not for our developer, Ross. I suspect he will figure this, so I will refer the thread to him.

    Anonymous
    #119122

    Ok, thank you.

    I await Ross’s response.

    Anonymous
    #119970

    Hi Ross, could you give me a direction?

    Ross Moderator
    #120061
    This reply has been marked as private.
    Anonymous
    #120095

    All right, thank you.

    Ross Moderator
    #120381
    This reply has been marked as private.
    Ross Moderator
    #120430
    This reply has been marked as private.
Viewing 10 posts – 1 through 10 (of 15 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.