wordpress query to get posts by post meta 1

wordpress query to get posts by post meta

 $args = array(
        'post_type'     => 'event_user',
        'meta_key'      => 'event_code',
        'meta_value'    => $fields[6]['value'],
        'meta_compare'  => '=='
    );

    $query = new WP_Query( $args );

// Other meta_compares
!=, LIKE, ==

Here is what the above code is Doing:
1. We’re creating a new WP_Query object.
2. We’re passing in an array of arguments to the WP_Query object.
3. We’re telling the WP_Query object to look for posts of the type ‘event_user’.
4. We’re telling the WP_Query object to look for posts with a meta_key of ‘event_code’.
5. We’re telling the WP_Query object to look for posts with a meta_value of $fields[6][‘value’].
6. We’re telling the WP_Query object to compare the meta_value to the value of $fields[6][‘value’].
7. We’re telling the WP_Query object to compare the meta_value to the value of $fields[6][‘value’] using the ‘==’ operator.

Similar Posts