Meta Query Within WP Query

I am going to show how to use meta query within the WP Query.

Most of the time we need meta query to find certain posts for category.

Or Let’s say you want to display the posts which has particular custom field value.

So for that you need meta query.

Here is the source code to use meta query within WP Query.

$args = array(
        'post_type' => '<post_type>',
        'post_status' 	=> 'publish',
  'meta_query' => array(
      'key' => '<acf_field>',
      'value' => '<field_value>',
      'compare' => '='
$loop = new WP_Query( $args );

I hope this will help you.

If you ran into any issues then kindly connect with me through the comments.

Than you.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories