Custom Post Type WP_Query with filters and search

This is what I ended up with: $specialty_terms = get_terms(‘specialty’); $specialty_term_ids = wp_list_pluck($specialty_terms, ‘slug’); $location_terms = get_terms(‘locations’); $location_term_ids = wp_list_pluck($location_terms, ‘slug’); if( isset($_GET[‘docname’]) ): $name_search = $_GET[‘docname’]; else: $name_search = “”; endif; if( isset($_GET[‘specialty’]) && $_GET[‘specialty’] !== ”): $specialty = $_GET[‘specialty’]; else: $specialty = $specialty_term_ids; endif; if( isset($_GET[‘location’]) && $_GET[‘location’] !== ”): $location = $_GET[‘location’]; … Read more

Can’t reset the secondary query by wp_reset_postdata()

wp_reset_query is meant to be used with a loop, because it resets the global $wp_query object. get_posts, on the other hand, just returns an array to be iterated with ie. foreach. setup_postdata does not populate the $wp_query object: https://codex.wordpress.org/Function_Reference/setup_postdata. For a custom query, you would either use the WP_Query class, or you could reset your … Read more

using custom meta user data to run queries in WordPress

wp_get_current_user() does not return all the data for the user, you should try using get_user_meta(). Try as below $company = get_user_meta($current_user->ID,’company’); $mf_group = get_user_meta($current_user->ID,’mf_group’); and in your post loop changes this two lines as below ‘company’ => $company[0], ‘mf_group’ => $mf_group[0], Hope this helps.

How to display author meta and count numbers for each user in comment.php?

Getting user’s metas values : $user_meta = get_user_meta($user_id, ‘YOUR_META_KEY’, TRUE); //You have to set the $user_id / And the “YOUR_META_KEY” can be description, name, custom meta… To get user’s comments count function commentCount($userId = null) { global $wpdb; if($userId == null) return 0; $count = $wpdb->get_var(‘ SELECT COUNT(comment_ID) FROM ‘ . $wpdb->comments. ‘ WHERE user_id … Read more