The WP_Meta_Query generator tool allows you to easily generate custom queries to filter WordPress posts, users, or terms based on metadata criteria. This tool is perfect for site administrators and developers who need to retrieve data based on custom fields without manually writing SQL queries.
Use our AI-driven interface to craft complex meta queries or select from preset options for quick query generation.
Getting Started
Query Variable Name
my_meta_query
Define a unique variable name for your query to prevent conflicts with other queries.
Meta Key
Enter the name of the custom field (meta key) you wish to filter by (e.g., last_login_date
).
Meta Value
Specify the value that the meta key should match (e.g., 2024-09-30
).
Compare
Choose a comparison operator to match the meta value, such as =
, !=
, >
, <
, or LIKE
.
Type
Specify the type of data stored in the meta key (e.g., NUMERIC
, CHAR
, DATE
) for proper comparisons.
Relation
If using multiple meta queries, define whether they should be related with AND
(all conditions must match) or OR
(any condition can match).
$args = array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'last_login_date',
'value' => '2024-09-30',
'compare' => '='
),
array(
'key' => 'user_status',
'value' => 'active',
'compare' => '='
),
),
);
$meta_query = new WP_Query( $args );
The WP_Meta_Query
class allows for advanced filtering based on custom metadata. You can filter posts, users, and terms by custom fields, combining multiple conditions to create complex queries. This tool simplifies the process of generating metadata queries, helping you avoid writing manual SQL.