WP_Query search for whole words

You’re gonna need regular expressions to accomplish that. First of all, you need to change ‘LIKE’ to ‘RLIKE’ (or ‘REGEXP’). Second, replace $keyword in ‘value’ with a regex that involves word boundaries. Like so: $queryArgs = array( ‘post_type’ => ‘faculty’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘proposed_keywords’, // name … Read more

Order by menu structure

You may be able to use a WP_Query on nav_menu_item since it is its own post type. I’ve never done this but maybe it would work like you need it to, worth a shot. There are three other possibilities: Option 1 – Get Your Nav Menu Items There’s a functions called wp_get_nav_menu_items() which will return … Read more

Order By Multiple Meta Fields

One problem with the query is that the self-join with the ambiguous WHERE gives you a crossed dataset (which is masked by the DISTINCT), so it would be simpler to use wp_post as a base to attach the joins that precisely match the keys, eg SELECT p.ID, key1.meta_value as prog_ongoing, key2.meta_value as prog_date_start FROM $wpdb->posts … Read more

order by multiple meta keys in pre_get_posts

Maybe a bit late … add_action( ‘pre_get_posts’, function($query) { if ( !is_admin() && $query->is_main_query() && is_post_type_archive( ‘[your_post_type]’ ) ) { $query->set(‘meta_query’, array( ‘_property_price’ => array( ‘key’ => ‘_property_price’, ), ‘_property_featured’ => array( ‘key’ => ‘_property_featured’, ) )); $query->set(‘orderby’,array( ‘_property_price’ => ‘DESC’, ‘_property_featured’ => ‘DESC’ )); } return $query; } );

Count posts returned by get_posts in external PHP script

The WordPress function get_posts() is making it’s own instance of WP_Query that is not globally accessible: function get_posts($args = null) { // … cut … $get_posts = new WP_Query; return $get_posts->query($r); } so you could instead try $results = get_posts($args); echo count($results); to give you the array count of post objects returned by get_posts(). WP_Query() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)