Listing posts with a value in a custom field

Assuming that this meta is for the post type “post” you could create a loop in two ways, get_posts or WP_Query. I also prefer the meta_query property over the meta_value and meta_key, because it adds the option to add more meta queries quicker as the array already exists. The get_posts method $posts = get_posts([ ‘post_type’ … Read more

User query – getting values for custom meta keys/fields

SOLVED. I missed ID field in field array. $args = array( ‘role’ => ‘author’, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_count’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘medical_diagnosis’, ‘compare’ => ‘EXISTS’, ), array( ‘key’ =’gender’, ‘compare’ => ‘EXISTS’, ), ), ‘who’ => ‘authors’, ‘count_total’ => true, ‘fields’ => array( ‘ID’, ‘user_email’, ‘display_name’), ); … Read more