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

    <?php } ?>
<?php } ?>

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.