The way you have built that query it is possible for you to have a bunch of empty values. For example, if grad
is not present then you end up searching ex_lokacija
keys for empty strings. Since your main relation is AND
all of the terms have to ‘hit’ so it seems likely to me that it would be very hard to get a query that returns anything. I would build the query to only search keys that have values.
$meta_query = array();
if (!empty($grad)) {
$meta_query[] = array(
'key' => 'ex_lokacija',
'value' => $grad ,
'compare' => 'LIKE'
)
}
// and so on for each of your keys, then
$args = array(
'post_type' => 'post',
'relation' => 'AND',
'meta_query' => $meta_query
)
$searched_posts = new WP_Query( $args );
Related Posts:
- WP_Query – Order results by meta value
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- Can I query custom meta data through WP_Query
- Meta Query with AND & OR?
- How do I search an array stored in a custom-field using WP_Query?
- How do I order by multiple custom fields using wp_query?
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Compare meta_query decimals not working right
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Using OR in WP_Query negates the “NOT EXISTS” compare
- WP_query : meta_key with custom rule for specific value
- How can I combine meta_query queries?
- How to filter a dd/mm/yyyy date from a custom field in a query
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Compare WP Custom Field date
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- Meta_query and numeric comparison [closed]
- Adding Custom Fields to Search
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Any way to include custom fields in WP_Query results?
- Multiple relationships in a query
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Conditional custom field query
- Order query by meta_value with multiple custom fields
- Auto Populate Custom Field with Complex Value That Increase by One?
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Passing meta_box string to post__in?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- meta_value and meta_key filtering returning no posts [closed]
- Select custom posts by meta_value and sort by a different meta value
- Can’t query by meta_key
- Adding custom field and querying from post table
- Meta query relation ‘OR’ not working as expected
- The best way to collision check in WP
- WP_query multiple custom fields not working
- Custom Query Fields – Altering Meta Value
- How to query for posts with either one or another custom field
- Multiple Custom Field Query
- How to update custom field of a posts in a particular category
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- WP Query multiple select form – meta_query help
- How to Order Posts by Custom Fields?
- WP_Query based on multiple metadata comparisons
- Complex WP_Query Using Post Date And Post Meta
- Display posts where date field matches current month?
- Show posts containing or not custom field
- Display agents (custom post type) alphabetically, except one who always shows last
- Query posts by Custom Meta (checkbox) & Genesis Grid Loop
- how to filter by last name for custom post
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Does wordpress have something like content-type?
- How to get and edit custom fields if in Quick Edit
- Create custom field on post draft or publish?
- How add a custom posttype name using ACF field to a query post array
- WordPress custom loop filter by meta_key and value with serialize data
- Create new post with meta data using WordPress API
- WPML & CFT: keeping custom field file to translation
- How to make condition, based on custom fields value?
- Order by empty custom field
- Add & store extra fields – WordPress Comments
- Outputing a metabox textarea and avoid line breaks inside li tags
- Restrict WordPress Search to Custom Field
- How to add a custom field to a post created programmatically?
- List all unique custom field values?
- “Matching” or “Linking” Two WordPress Pages: Custom Fields?
- Build index page from custom fields
- Get text from user and display it on page
- Upload & include specific JavaScript files for posts?
- help for user login
- How to store meta field values
- Order by custom date field
- Group Posts By Custom Meta Value: Date
- Custom Field: how to save array of multiple key-values in WordPress
- How can I detect user’s timezone?
- WP_Query get always custom post_type for first
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- meta query multiple values for the same key
- Custom post types – meta_query: search lesson which starts sooner
- Showing the post only when there is title, thumbnail and the content in Custom Fields
- ACF Post Object meta-query by title not ID
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Custom field group on page
- How to filter post using custom feild value in shortest and longest duration?
- Crop custom image size vs actual size