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']){ ... } }
get_post_meta()
is needed - KAGG Design