php - Count posts with meta value -


i'm trying show number of posts have meta key values current user.

this code:

    $args = array(     'posts_per_page'    => -1,     'post_type'         => 'post',     'post_status'       => 'publish',     'author'            => $current_user_id,     'meta_query'        => array(            'key'        => 'color',            'value'      => array('red', 'blue')     ), ); $posts_array = get_posts( $args ); $the_count = count($posts_array);  echo $the_count; 

thi counting all posts current user, ignoring meta key values.

i need $the_count number of posts have meta key value 'red' or 'blue' current user.

what doing wrong?

thanks in advance!

i not sure, try this:

$args = array(     'posts_per_page'    => -1,     'post_type'         => 'post',     'post_status'       => 'publish',     'author'            => $current_user_id,     'meta_key'          => 'color',     'meta_value'        => array('red', 'blue') );  $posts_query = new wp_query($args); $the_count = $posts_query->post_count;  echo $the_count; 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -