Suppose there is an arbitrary type created using register_post_type('custom_type'...)
Such a query will output all entries of this type:

 $args = array( 'post_type' => 'custom_type', ); $query = new WP_Query( $args ); 

But this record type has arbitrary fields, and you need to access these fields in the $ query array (fields from the wp_postmeta table) so that you can sort them during the construction of the markup.
those. in order not to make several queries to the database, making a selection using meta_query , how can you make one request, and then output records, depending on an arbitrary field?
By default, this query is $query = new WP_Query( $args ); displays only data from the wp_post table. And you also need to attach data from the wp_postmeta table to this array.
How to do it?

PS

 $args = array( 'post_type' => 'custom_post', 'meta_query' => array( array( 'key' => 'some_key', ) ) ); $query = new WP_Query( $args ); 

this code does not add data to the $ query array

PS

 $args = array( 'post_type' => 'custom_post', 'meta_query' => array( array( 'key' => 'some_key', ) ) ); $query = new WP_Query( $args ); if( $query->have_posts() ){ while( $query->have_posts() ){ $query->the_post(); if(isset($query['price']){ ... } if(isset($query['wired']){ ... } } 
  • @KAGG Design, meta_query does not add data to the $ query array. - word
  • This means that you use it correctly, nothing else. - KAGG Design
  • Where do you have value or EXISTS / NOT EXISTS in your code? You read carefully what is written on kama - KAGG Design
  • And in the question you have mixed horses, people. Data from postmeta can not be pushed into $ query. But at the same time you are talking about sampling by arbitrary fields. Meta_query is needed for the selection, to get the field from the post in $ query - get_post_meta() is needed - KAGG Design

0