Problems not showing the first three notes highlighted with Query in wordpress

1

I'm doing this site web where I have three outstanding notes and below the rest of the notes uploaded, which I would like to do is that in those below I do not show the ones that are already up, that I do not repeat them. The problem is that I do not know how to use the query to get them out.

<!-- NOTAS DESTACADAS -->
            <?php 
                $home_args = array(
                'post_type'   =>  'post',
                'meta_query' => array(
                  array(
                    'meta_key'     => 'notas_destacadas',
                    'value'   =>  '1',
                    'compare' => '!=',
                    'orderby' =>  'meta_value_num',
                'order'       =>  'DESC',
                  ),
                ),
                
                'showposts'   =>   3, 
                );                
                $wp_query_home = new WP_Query( $home_args );

                if ($wp_query_home-> have_posts ()) {
                  while ($wp_query_home-> have_posts ()) {
                    $wp_query_home-> the_post ();
            ?>

<!-- NOTAS DESTACADAS FINAL -->

              <?php 
                  $home_args = array(
                  // 'post__not_in' => array( '1,2,3' ),            
                  'post_type'   =>  'post',
                  'orderby'     =>  'meta_value_num',
                  'order'       =>  'DESC',
                  'showposts'   =>   8, 
                  );
                  $wp_query_home = new WP_Query( $home_args );

                  if ($wp_query_home-> have_posts ()) {
                    $counter = 0;

                    while ($wp_query_home-> have_posts ()) {
                      $wp_query_home-> the_post ();
              ?>            
              <!-- fila 1 -->
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 lib-item">
                    <a href="<?php the_permalink(); ?>"> 
                      <div class="lib-panel">
                          <div class="row box-shadow">
                              <div class="col-md-4">
                                  
                                   <figure class="snip1208" style="width: 100%;">
                                    <?php echo get_the_post_thumbnail(); ?>
                                      <!-- <img class="image img-responsive" src="images/destacada1.png" alt="..."/> -->
                                  
                                      <?php if(get_field('agregar_icono_a_la_nota')): ?> 
                                      <div class="date">
                                        <img class="icon image img-responsive" src="<?php the_field('imagen_icono_nota') ?>" alt="...">
                                      </div> 

                                      <?php  endif; ?> 
                                     
                                    </figure>                                 
                              </div>
                              <div class="col-md-8 lib-panel">
                                <div class="contenido">
                                    <div class="author">
                                        <span><?php echo get_the_date();  ?></span>
                                       
                                        <a href="<?php the_permalink(); ?>" title="<?php cortarTexto(get_the_title(  ), 300,"") ?>"><h4><?php cortarTexto(get_the_title(  ), 30,"...") ?></h4></a>
                                    </div>
                                    <div>
                                      <p><?php cortarTexto(get_the_excerpt(  ), 100,"...") ?></p>
                                    </div>

                                </div>
                              </div>
                          </div>
                      </div>
                    </a>
                </div>

              <?php
               $counter++;
                if ($counter == 2) { 
                     ?>
                         <div class="clearfix"></div>
                         <br>
                          <?php 
                          $counter = 0;
                        }
                }
              }          
              ?>               
               <?php wp_reset_query(); ?>
    
asked by MarianoF 27.03.2018 в 16:24
source

2 answers

1

As I see what you want to do is that the last three posts are shown as highlights and all the others in the section below.

One way to do this could be to indicate in the query that it does not show the last three post, you could modify it like this:

 <?php 
                  $home_args = array(
                  'offset'      =>  3,            
                  'post_type'   =>  'post',
                  'orderby'     =>  'meta_value_num',
                  'order'       =>  'DESC',
                  'showposts'   =>   8, 
                  );
                  $wp_query_home = new WP_Query( $home_args );

                  if ($wp_query_home-> have_posts ()) {
                    $counter = 0;

                    while ($wp_query_home-> have_posts ()) {
                      $wp_query_home-> the_post ();
              ?>    

Notice that I have added the offset parameter that is used to exclude the last posts defined in their value, in this case you exclude three posts.

    
answered by 28.03.2018 / 09:17
source
2

You can filter the second query using the IDs of the first query using wp_list_pluck link

$primer_query_ids = wp_list_pluck( $primer_query->posts, 'ID' );

Then you exclude the posts in the second query by adding:

'post__not_in' => $primer_query_ids,
    
answered by 31.03.2018 в 22:59