1

I am running a loop which requires content from multiple meta_values. I have a meta key called 'content_type'. Attached I have three meta_values for the key.

My code...

<?php $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
      $query_args = array(
      'post_type' => 'post',
      'meta_key' => 'content_type',
      'meta_value' => 'news',
      'posts_per_page' => 3,
      'paged' => $paged
      );
      $the_query = new WP_Query( $query_args );
?>

I need to show content from THREE meta_values. 'news', 'videos' and 'recipes'. My code currently pulls from only one - 'news'.

What is the best way to pull from all three?

1 Answer 1

1

I suggest meta query -- https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters. In your case smth in this fashion:

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

$args = array(
    'post_type'  => 'post',
    'paged' => $paged
    'posts_per_page' => 3,
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key'     => 'content_type',
            'value'   => 'news',
            'compare' => '=',
        ),
        array(
            'key'     => 'content_type',
            'value'   => 'videos',
            'compare' => '=',
        ),
        array(
            'key'     => 'content_type',
            'value'   => 'recipes',
            'compare' => '=',
        ),
    ),
);
$query = new WP_Query( $args );

I am not sure how the custom field is stored in the database with ACF ( with or without "_" check it please )

Sign up to request clarification or add additional context in comments.

1 Comment

That's makes perfect sense, but not quite working as is. Output says I have no posts. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.