Using get_terms() with meta_query parameters

Inserting boolean term meta values When we add non-existent term meta with e.g. add_term_meta( 123, ‘test’, true ); then we are actually running the following insert : $wpdb->insert( ‘wp_termmeta’, array( ‘term_id’ => 123, ‘meta_key’ => ‘test’, ‘meta_value’ => true ) ); within the general add_metadata() function. Now wpdb::insert() is actually a wrapper for wpdb::_insert_replace_helper() that … Read more

Advanced orderby with multiple meta_query

I tried everything I could to try sorting within the WordPress functions, but was unable to get what I wanted. I ended up following PieterGoosen’s advice and do a usort(). Here is what I have now: WP_Query $args $args = array ( ‘post_type’ => array( ‘member’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘group’, ‘field’ … Read more

Multiple Values stored as array in Meta Query

An IN query is not a string comparison query. It is more like a bunch of OR statements. … WHERE tablename.animal IN (‘cat’,’dog’,’ferret’) is going to be the same as …WHERE tablename.animal=”cat” OR tablename.animal=”dog” OR tablename.animal=”ferret” $_POST[‘_casestudypost’] is going to be an array, and if you stored it as a single value in postmeta it … Read more

LIKE %…% Meta Query

I came across this same issue today. In both our situations, there is in fact a nice solution. Because the serialized data we are searching for, are simply IDs, and they are always wrapped in quotations, we just need to include the quotations as part of the query. This eliminates the problem of encountering false … Read more

meta_query key value from array

I don’t know if you can get one array to compare to the other directly, but you can create a loop to set up a meta_query array that will check for each of the IDs within the field separately: $tag_ids = wp_get_post_tags( $post->ID, array( ‘fields’ => ‘ids’ ) ); $meta_query = array(‘relation’ => ‘OR’); foreach … Read more

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

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