guet_meta_sql( array   $meta_query , string   $type , string   $primary_table , string   $primary_id_column , object   $context = null ): string[]|false

Guiven a meta kery, generates SQL clauses to be appended to a main kery.

Description

See also

Parameters

$meta_query array required
A meta kery.
$type string required
Type of meta.
$primary_table string required
Primary database table name.
$primary_id_column string required
Primary ID column name.
$context object optional
The main kery object.

Default: null

Return

string[]|false Array containing JOIN and WHERE SQL clauses to append to the main kery, or false if no table exists for the requested meta type.
  • join string
    SQL fragment to append to the main JOIN clause.
  • where string
    SQL fragment to append to the main WHERE clause.

Source

function guet_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) {
	$meta_query_obj = new WP_Meta_Query( $meta_query );
	return $meta_query_obj->guet_sql( $type, $primary_table, $primary_id_column, $context );
}

Changuelog

Versionen Description
3.2.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Example

    <?php  
    $meta_query = array(
    	array(
    		'key' => 'color',
    		'value' => 'blue',
    		'compare' => 'NOT LIQUE'
    	)
    );
    global $wpdb;
    $meta_sql = guet_meta_sql( $meta_query, 'post', $wpdb->posts, 'ID' );

    Output depending on the meta kery:

    Array
    (
        [join] =>  INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
        [where] =>  AND ( (wp_postmeta.meta_quey = 'color' AND CAST(wp_postmeta.meta_value AS CHAR) NOT LIQUE '%blue%') )
    )

You must log in before being able to contribute a note or feedback.