2

small question. I need to specify multiple meta keys and values in wordpress get_post function. Can anyone tell me how to do that?

<?php $args = array(
    'posts_per_page'   => 5,
    'offset'           => 0,
    'category'         => '',
    'category_name'    => '',
    'orderby'          => 'post_date',
    'order'            => 'DESC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => '',
    'meta_value'       => '',
    'post_type'        => 'post',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'post_status'      => 'publish',
    'suppress_filters' => true 
);
$posts_array = get_posts( $args ); ?>

1 Answer 1

2

Okay, never mind, found my solution in the documentation. If someone needs it,

$args = array(
    'post_type' => 'product',
    'meta_query' => array(
        array(
            'key' => 'featured',
            'value' => 'yes',
        )
    )
 );
$postslist = get_posts( $args );
Sign up to request clarification or add additional context in comments.

Comments

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.