0

I'm doing a simple WP_query for three post types: 'post', 'sal', 'product' ('product' is a default post type of WooCommerce plugin and 'sal' is a custom post type).

The strange thing is that a query with only two post types ('post', 'sal') returns more (!!) values than the original query with three post types.

Is it possible? I'm inspecting de code again and again and I don't find the error. Some clue to research will be wellcome.

The query and the loop is this:

<?php if (is_home()) {
  $colores_args = array (
    'post_type'         => array( 'post', 'sal', 'product' ),
    'meta_key'          => 'portada',
    'meta_value'        => 'yes',
  );
  $colores_query = new WP_Query( $colores_args );
  ?>

  <div class="colores">
    <?php
    $colores = array();
    // The Loop
    if ( $colores_query->have_posts() ) {
        while ( $colores_query->have_posts() ) {
            $colores_query->the_post();
        $este_color = get_field('color');
        $colores[] = $este_color;
        }
    } else {
        // no posts found
      echo 'no';
    }
    // Restore original Post Data
    wp_reset_postdata();
    $colores_uniq = array_unique($colores);
    foreach ($colores_uniq as $color) { ?>
      <a class="boton-color" style="background-color:<?php echo $color;?>">

      </a>
    <?php } ?>
  </div>
<?php } ?>
0

My fault: missing

'posts_per_page'    =>  -1,

in the query

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.