Return posts with specific meta key first, but the rest in alpha order by last name

This may not be the best method, but I was able to achieve my desired result. I ended up setting up a second query. functions.php // List staff member by last name function posts_orderby_lastname ($orderby_statement) { $orderby_statement = “RIGHT(post_title, LOCATE(‘ ‘, REVERSE(post_title)) – 1) ASC”; return $orderby_statement; } staff-grid.php echo ‘<table>’; echo ‘<tr>’; // Query … Read more

Trying to perform complex custom field query with order by set to field value

If the value of your custom fields is numeric, you could try ordering with meta_value_num. Also note that both meta_value and meta_value_num require meta_key in the query as described here. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => $number, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘meta_key’ => ‘event-start’, ‘value’ => $today_is, ‘type’ => ‘NUMERIC’, … Read more

Search multiple meta keys at once

You’ll want to use the ‘meta_query’ argument of WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) Here’s a snippet that uses two separate meta key comparisons: $query_args = array( ‘post_type’ => ‘event’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘_start_date’, ‘meta_query’ => array ( array( ‘key’ => ‘_start_date’, ‘value’ => $_start_of_month, ‘compare’ => ‘>’, ), array( ‘key’ => … Read more

WP_Query meta_query where meta value ends in space

Note sure how your structure is, but here’s one way, using RLIKE comparison and a space character class: array( ‘key’ => ‘_address_postcode’, ‘value’ => ‘^SC1[[:space:]]’, // Starts with ‘SC1 ‘ ‘compare’ => ‘RLIKE’ ) Maybe you should consider adjusting the meta values, as suggested by @cybmeta? But note that meta queries can be slow, so … Read more

WP REST API: Order posts by meta value (acf)?

I’m guessing you haven’t exposed meta_key and meta_value to the REST API with the rest_query_vars filter, so this should do it: function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array (‘meta_key’, ‘meta_value’)); return $current_vars; } add_filter (‘rest_query_vars’, ‘my_add_meta_vars’); Then you can refer to meta_key and meta_value in your query. Be aware that this obviously exposes … Read more

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