1

Have a CPT with custom field "size" valued "big" or "small" and Author with custom radio field "gender". Author can be "Man" or "Woman". Need query posts if, for example, author is "man" and filed "size" is "big". Try something like this:

$args = array(
  'post_type' => 'custom_post_type',
  'meta_query' => array(
    array(
        'key'     => 'size',
        'value'   => 'big',
        'compare' => 'LIKE',
    )
  )
);
$query = new WP_Query( $args );

This show posts with key value "big" from all authors, but how add author with key "gender" valued "man" to this query?

0

By adding another array

   $args = array(
      'post_type' => 'custom_post_type',
      'meta_query' => array(
        array(
            'key'     => 'size',
            'value'   => 'big',
            'compare' => 'LIKE',
        ),
        array(
            'key'     => 'gender',
            'value'   => 'male',
            ),
      )

);
$query = new WP_Query( $args );

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.