Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro
Docs

The PHP API

Finding posts by their fields: ugly_find()

No meta_query. You say what the fields must be.

1 minute to read Updated 6 days ago

PHP
$q = ugly_find( 'recipe', array(
	'difficulty' => 'easy',                    // equal to
	'minutes'    => '< 30',                    // < <= > >= !=
	'cuisine'    => array( 'italian', 'french' ), // any of these
	'vegan'      => true,                      // yes (false: no)
	'note'       => '~pasta',                  // contains
	'price'      => 'between 5 and 10',
	'author'     => $author_id,                // a relation that points at this post
), array( 'order' => 'minutes asc', 'limit' => 12 ) );

while ( $q->have_posts() ) {
	$q->the_post();
	// the loop
}
wp_reset_postdata();

It gives a normal WP_Query, so the loop is the one you know.

What a value can be

Value Meaning
'easy', 12 Equal to
'< 30', '<= 30', '> 5', '>= 5', '!= x' A comparison. Numbers are compared as numbers
'between 5 and 10' Between two values, included
'~text' Contains
'empty', 'filled' Has nothing in it, or has something
array( 'a', 'b' ) Any of them
true, false Yes or no
A post A relation that points at that post

Options

Option What it does
order 'minutes desc', 'title', 'date', 'random'
limit How many (default: WordPress' own)
page Which page of results
status The post status
search A word to search for
published When WordPress says it was published: 2026, 'this year', 'this month', 'last 30 days', 'after 2026-05-20', 'between 2026-01-01 and 2026-03-31'

Did this article answer your question?