Given a meta query, generates SQL clauses to be appended to a main query.
<?php get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context ); ?>
(array) array( 'join' => $join_sql, 'where' => $where_sql ).
<?php $meta_query = array( array( 'key' => 'color', 'value' => 'blue', 'compare' => 'NOT LIKE' ) ); global $wpdb; $meta_sql = get_meta_sql( $meta_query, 'post', $wpdb->posts, 'ID' );
Output depending on the meta query:
Array ( [join] => INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) [where] => AND ( (wp_postmeta.meta_key = 'color' AND CAST(wp_postmeta.meta_value AS CHAR) NOT LIKE '%blue%') ) )
Since: 3.2.0
get_meta_sql() is located in wp-includes/meta.php
.