Search custom post type posts only by meta fields?

This might work, not tested though. First add this to join the postmeta table: add_filter( ‘posts_join’, ‘search_filters_join’, 501, 2 ); function search_filters_join( $join, $query ) { global $wpdb; if ( empty( $query->query_vars[ ‘post_type’ ] ) || $query->query_vars[ ‘post_type’ ] !== ‘product’ ) { return $join; // skip processing } if ( ($this->is_ajax_search() || $this->is_search_page()) && … Read more

Query a meta key using an array of values where the database value is a string

You could use multiple meta clauses in your WP_User_Query, along with a LIKE comparison. Something like $args = array( ‘role’ => ‘member’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘specializations’, ‘value’ => ‘doctor’, ‘compare’ => ‘LIKE’, ), array( ‘key’ => ‘specializations’, ‘value’ => ‘researcher’, ‘compare’ => ‘LIKE’, ), ), ); $found_users = new … Read more

WordPress show content if current user get spesific role and spesific meta value

Your question needs some additional context, but here’s a generic approach to what you’ve described. if ( is_user_logged_in() ) { $user = wp_get_current_user(); // Does user have the required role? if ( in_array( ‘some_role’, $user->roles ) && ‘some_meta_value’ == get_user_meta( $user->ID, ‘some_meta’, true ) ) { // Special content… } else { // User doesn’t … Read more

Sorting past events by month

Using query_posts is pretty much always a bad idea as it causes another database query but it also will break pagination and can cause other issues as well. What you need it a filter on pre_get_posts. function pgp($qry) { if (!is_admin() && is_main_query() && $qry->is_category(3709)) { $qry->set(‘orderby’,’meta_value’); $qry->set(‘meta_key’,’Deadline’); //formatted YYYYMMDD $qry->set(‘ignore_sticky_posts’,true); } return $qry; } … Read more