0

I have the following code but it is only returning the latest 6 post instead of the conditions in the meta query. What am I doing wrong that it is ignoring the meta_query?

I have tried different conditions as well and still only the latest 6 posts are returned.

$Args  = array(  'post_type'            => 'equipment',
                         'posts_per_page'       => 6,
                         'post_status'          => 'publish',
                         'meta_query' => array(
                                                array(
                                                    'key' => 'price',
                                                    'value' => 5000,
                                                    'compare' => '<='
                                                )
    )
                      );

        $Query = new WP_Query( $Args );

        if($Query->have_posts())
        {

          $HTML =  '<div class="row">';

          foreach($Query->posts as $Post)
          {


            $Meta  = get_post_meta($Post->ID);

            $Image = get_the_post_thumbnail($Post->ID,'thumbnail');
            $HTML .= '<div class="col-md-4">
                            <a href="" title="">'.$Image.'</a>
                        <div class="product-info">
                              <h3 class="" style="margin-bottom:15px">
                                    <a style="color:#ff750c !important" href="" title="'.$Post->post_title.'">
                              '.$Post->post_title.'</a>
                              </h3>
                          <div>
                            <strong class="yellow-text">Regular Price: $'.number_format($Meta['price'][0],2).'</strong>
                          </div>
                          <div style="color:#ff750c;"><strong>Sale Price: $'.number_format($Meta['sale_price'][0],2).'</strong></div>
                        </div>
                    </div>';

          }

          $HTML .=  '</div>';

        }
user3098629
  • 175
  • 1
  • 1
  • 13
  • 1
    Maybe because the last 6 posts have a price lower than or equal to 5000. It cannot be deduced from your question what is in your database… – Klaassiek May 20 '23 at 20:37
  • That is not correct. They are all well over. Thanks anyway. – user3098629 May 20 '23 at 20:38
  • Dude, it's really hard to say anything based on a piece of code. You tried to specify `type` in `meta_query`? – imhvost May 20 '23 at 20:59
  • It's fine. I wanted to make sure that the code was correct but I think I have found the problem. It wasn't a meta query as I thought but a taxonomy query. Anyway. Thanks – user3098629 May 20 '23 at 21:01

0 Answers0