0

I have this page that shows posts from a range of years selected of a form on a previous page. the first results display the 10 posts as set in args(post_by_page => 10); if there are more posts I use wp_pagenavi() plugin. But it doesn't display the rest of the posts.

<?php  
if(isset($_POST['paisx']) && !empty($_POST['paisx'])){ $pais = $_POST['paisx']; $pais_explode = explode('|', $pais); /*echo "El id es: "; echo $pais_explode[0]; echo "El pais: "; echo $pais_explode[1]; */ }
if(isset($_POST['nivellegislativo']) && !empty($_POST['nivellegislativo'])){ $nivelley = $_POST['nivellegislativo']; $result_explode = explode('|', $nivelley); /*echo "El nivel legislativo: "; echo $nivelley[0];*/}
 if(isset($_POST['MisEstados']) && !empty($_POST['MisEstados'])){   $estado = $_POST['MisEstados']; $estado_explode = explode('|', $estado); /*echo "El id del estado es: "; echo $estado_explode[0]; echo $estado_explode[1];*/ } 
//$fechaaprobacion = $_POST['fecha_de_aprobacion']; $fechas_explode = explode('|', $fechaaprobacion); echo "La fecha de aprobacion es: "; echo $fechas_explode[1];
if(isset($_POST['anox']) && !empty($_POST['anox'])){ $anoinicio = $_POST['anox']; }
if(isset($_POST['anofin']) && !empty($_POST['anofin'])){ $anofin = $_POST['anofin']; }
  ?>
<?php get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>

<section class="titulos b-b b-t b-dark p-b-10 p-t-10">
    <div class="row">
        <div class="col-sm-12 sm-m-t-30 sm-p-t-20 sm-p-b-20">
            <h1 class="light text-dark xs-p-t-30 sm-p-b-30">
                Leyes
                <?php

if(isset($result_explode[1])){ 
//Aqui va tu codigo 

switch ( $result_explode[1]) 
    {
    case "Federal":
        echo " federales";
        break;
    case "Estatal":
        echo " estatales";
        break;
   case "Local":
        echo " locales";
        break;
    case "Judicial":
        echo " judiciales";
        break;        

    default:
        echo " en todos los niveles legislativos"; 
    }

}

switch ($pais) 
    {
    case "todos":
        echo " de todos los paises";
        break;
    case "":
        echo " de todos los paises";
        break;

    default:

echo " en ";

              wp_reset_query();
                  $paises = new WP_Query(

                  array(
                      'post_type' => 'pais',
                      'posts_per_page' => 1,
                      'order' => 'asc',
                      'orderby' => 'id',
                      'post_status' => 'publish',
                      'p' => $pais_explode[0],

                  )
              ); 

              if ( $paises->have_posts() ) : 

                while ( $paises->have_posts() ) : $paises->the_post(); 

                    $elpais = the_title();
                     endwhile; 

                  endif; 
                 wp_reset_query();  

    }


   switch ($estado) 
    {
    case "todos":
        echo " de todos los estados";
        break;
    case "":
        echo " de todos los estaods";   //PAGE 2 STOPS HERE
        break;

    default:

echo " del estado de  ";

              wp_reset_query();
                  $estados = new WP_Query(

                  array(
                      'post_type' => 'estado',
                      'posts_per_page' => 1,
                      'order' => 'asc',
                      'post_status' => 'publish',
                       'p' => $estado_explode[0],

                  )
              ); 

              if ( $estados->have_posts() ) : 

                while ( $estados->have_posts() ) : $estados->the_post(); 
                     the_title(); 
                     endwhile; 

                  endif; 
                 wp_reset_query();  
    }

 ?>
            </h1>

        </div>
    </div>
</section>
<section class="legislacion">
<div class="row">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-12 m-t-20">

                <?php 

function where_pais( $elpais ) {
  $elpais = str_replace("meta_key = 'cobertura_%", "meta_key LIKE 'cobertura_%", $elpais);
  return $elpais;
  }

add_filter('posts_where_pais', 'where_pais');

function where_estado( $elestado ) {
  $elestado = str_replace("meta_key = 'cobertura_%", "meta_key LIKE 'cobertura_%", $elestado);
  return $elestado;
  }

add_filter('posts_where_estado', 'where_estado');

wp_reset_query();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$paises = array('relation' => 'OR'); 

if  ($pais != "todos")  {
    array_push($paises, array('key' => 'pais_iniciativa', 'value' => $pais_explode[1], 'compare' => 'LIKE'));  
    array_push($paises, array('key' => 'cobertura_%_pais', 'value' => '"'.$pais_explode[0].'"', 'compare' => 'LIKE'));

} else {

    array_push($paises, array('key' => 'pais_iniciativa',  'compare' => 'EXISTS')); 
    array_push($paises, array('key' => 'cobertura_%_pais', 'compare' => 'EXISTS'));
}

$estados = array('relation' => 'OR'); 
if  ($estado != "todos")  {
    array_push($estados, array('key' => 'estado', 'value' => $estado_explode[1], 'compare' => 'LIKE'));
    array_push($estados, array('key' => 'cobertura_%_estado', 'value' => '"'.$estado_explode[0].'"', 'compare' => 'LIKE'));

} else {

}

$niveles =  array('relation' => 'OR'); 
if  ($nivelley != "todos")  { 
    array_push($niveles, array('key' => 'nivel_legislativo', 'value' => $result_explode[0], 'compare' => '='));
    array_push($niveles, array('key' => 'nivellegislativo', 'value' => $result_explode[1], 'compare' => 'LIKE'));

} else  {
    array_push($niveles, array('key' => 'nivel_legislativo',  'compare' => 'EXISTS'));
    array_push($niveles, array('key' => 'nivellegislativo',  'compare' => 'EXISTS'));
}

$temp = array('relation' => 'AND'); 

array_push($temp, $paises);
array_push($temp, $estados);
//array_push($temp, $niveles);

if ($anoinicio != "todos") {

                $loop = new WP_Query( array( 
                    'post_type' => 'iniciativas',
                    'paged' => $paged,
                    'numberposts' => '-1',
                    'posts_per_page' => '10',
                    'date_query' => array(
                                                array(
                                                    'after'    => array(
                                                        'year'  => $anoinicio,
                                                        'month' => 01,
                                                        'day'   => 01,
                                                    ),
                                                    'before'    => array(
                                                        'year'  => $anofin,
                                                        'month' => 12,
                                                        'day'   => 31,
                                                    ),
                                                    'inclusive' => true,
                                                ),
                                            ),
                    'meta_query' => $temp
                     ) 
                );


} else  {

 $loop = new WP_Query( array( 
                    'post_type' => 'iniciativas',
                    'paged' => $paged,
                    'numberposts' => '-1',
                    'posts_per_page' => '500',
                    'meta_query' => $temp

                     ) 
                );

} 

     if ( $loop->have_posts() ) :
        while ( $loop->have_posts() ) : $loop->the_post(); 
          $bibliografia = get_post_meta(get_the_ID(), 'bibliografia', true);
          $pais_cf = get_post_meta(get_the_ID(), 'pais', true);
          $documento_iniciativa = get_post_meta(get_the_ID(), 'documento_iniciativa', true); 
 ?>


<div class="ley m-t-30">
    <p><?php $fecha_de_aprobacion = get_field('fecha_de_aprobacion'); if($fecha_de_aprobacion != "") { echo "Fecha de aprobación ".  $fecha_de_aprobacion; } else { echo "Publicada el ";  the_time('j \d\e F  \d\e Y'); } ?></p>
                <h4><a href="<?php the_permalink(); ?>" class="text-dark"><?php the_title(); ?></a> <?php /*echo $postidpais; */ ?></h4> 

                </div>
                <?php endwhile;  ?>



<?php       endif;?>

            </div>

        </div>
    </div>  
</div>
<!--NAVEGACION-->

    <div class="clear"></div>

  <div class="row">
              <div class="col-sm-3 col-sm-offset-5 m-t-40 bg-pink-light" style="text-align: center; padding:10px"> <?php wp_pagenavi(array( 'query' => $loop ) );  ?></div>
      </div>
</section>
<?php wp_reset_query(); ?>
<?php endwhile; // end of the loop.  ?>
<?php get_footer(); ?>

It seems that the query is null on the second page. Also it only displays results from up to the year 2016 even if I have posts of 2019. I can't seem to find where the error is. Any help would be great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.