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

Functions

ugly_find()

1 minute to read Updated 1 week ago

PHP
ugly_find( string|array $post_type, array $where = [], array $options = [] ): WP_Query

Finds posts by the value of their fields, with no meta_query to write.

Parameter Meaning
$post_type A post type, or a list of them
$where field name => what it must be
$options order, limit, page, status, search

Returns: a normal WP_Query, so you use it in the usual loop.

PHP
$q = ugly_find(
	'recipe',
	array(
		'difficulty' => 'easy',
		'minutes'    => '< 30',
		'cuisine'    => array( 'italian', 'french' ),
	),
	array(
		'order' => 'minutes asc',
		'limit' => 12,
	)
);

while ( $q->have_posts() ) {
	$q->the_post();
	the_title( '<h2>', '</h2>' );
}
wp_reset_postdata();

What a value in $where can be

You write It means
'easy' or 5 Is equal to
'< 30', '>= 5', '!= x' Compared with
'between 5 and 10' In that range
'~text' Contains
'empty' / 'filled' Has no value / has one
array( 'a', 'b' ) Is any of them
true / false Yes / no
a post A relation that points at that post

Did this article answer your question?