Forums › Forums › Search & Filter Pro › Edit Query Arguments and Pagination Problem
Tagged: arguments, edit, meta_query, pagination, query
- This topic has 14 replies, 3 voices, and was last updated 7 years, 4 months ago by Anonymous.
-
Anonymous(Private) July 4, 2017 at 5:53 pm #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.
Anonymous(Private) July 6, 2017 at 5:24 pm #119108I 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; }; ?>
-
AuthorPosts