Functions
ugly_find()
ugly_find( string|array $post_type, array $where = [], array $options = [] ): WP_QueryFinds 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.
$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?
Thank you. It helps us make the documentation better. Need more help?