Questions tagged [meta-query]

Refers to a mechanism built into the WP_Query class for querying the database for post data, including pages and CPTs, based upon post meta data.

Filter by
Sorted by
Tagged with
0
votes
0answers
7 views

meta_query contains IN array

This is probably not possible... But my experience with wordpress is that "everything" is possible(Just have to find the correct workaround :-) . So I hope someone has a solution for this. I have the ...
0
votes
0answers
14 views

How can I show all posts, even ones that lack the given meta_key, when using orderby in WP_Query?

I have some businesses: +---------------+--------+ | business_name | rating | +---------------+--------+ | McDonald's | 3.9 | | Subway | 4.1 | | Pizza Hut | 4.3 | | TGI Friday'...
0
votes
2answers
440 views

Extending WP Query: Custom geolocation meta values work, but tax_query breaks

I've built a custom query for geolocation searches. I'm saving lat and lng within each custom post type as a meta value. My query extension returns results successfully when lat and lng are the only ...
2
votes
1answer
599 views

WP_Query min and max values

I'm building a houses class and I want to filter these houses with a query. But don't get any results: Example house: Min price: 10 Max price (field not required): empty I've a price filter ...
1
vote
2answers
3k views

Using Query Posts With Multiple Post Types And A Taxonomy

I am developing a site that has two different custom post types; one of them is called Articles and one is called Sketchpad. Sketchpad is user submitted content that is assigned a custom taxonomy term ...
2
votes
1answer
456 views

How to count data records in wordpress which have same meta_value in wp_postmeta table?

I want to get number or count of same meta_value of meta_key == 'parent_id'.How can i get it? What should be the wordpress query for counting records in same table? //set the meta_key to the ...
0
votes
2answers
464 views

WP_Query returns empty if meta_query has more than 7 values

I have a custom loop to display a custom post type 'properties' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if ...
1
vote
1answer
618 views

Order by custom field value not working for acf date field

I have custom post type event which has custom field event_date. The date format for this field is set to Ymd. I'm trying to get posts in order of event_date Here is the code to pull the posts in ...
0
votes
3answers
462 views

Sort posts by post views and consider meta key

my code should show popular posts where the meta key "slider" isn't empty. Have anyone an idea why it doesn't work? The problem is that this code only shows posts with a slider image. But it ignores ...
0
votes
1answer
20 views

Display posts every specific day

i want to display posts every specific day like post should desplay in evry friday with meta key acf date picker <?php $todayName = date('l'); $schedules = new WP_Query(array( ...
0
votes
1answer
805 views

Extending woocommerce admin product search

I have added custom fields to products but searching in admin page does not work. Tried many codes and found this one that finally works here but it removes default searching by title so search by ...
0
votes
0answers
12 views

sort posts on front end using url query

I am trying to sort posts on my archive page based off a custom field. The custom field is a number. I have the following in my functions.php file - function wpse139657_orderby(){ if( isset($_GET[...
0
votes
1answer
31 views

Query against multiple locations within single custom post type post

I have a custom post type for "Events" and each event can have a variable amount of "Locations" (lat/lng) which is stored as meta. I need to be able to get "Event" posts based on the bounds of a map. ...
0
votes
1answer
628 views

Exclude posts with certain meta data from search results

I'm trying to exclude al posts with certain meta data from the search results but so far it's not working. Here's the code I'm using: function ZoekGeenLegeItems( $query ) { if( is_admin() || !$...
0
votes
1answer
525 views

Pagination not working on my archive page for a custom post type

First off I have a custom post type called events, and I wrote a custom query in in my archive-events.php file. Everything is working great except for the pagination. To trouble shoot I stripped ...
0
votes
1answer
656 views

wp_Query with 4 post meta feald arguments gives 500 internal server error

I am creating a custom plugin to search for custom post type provided with 4 meta field arguments. I am using wp_Query() to fetch the search results. My Query string is. $args = array( ...
0
votes
1answer
582 views

shortcode order for event custom post type

ok im working on a website using post type event with post_meta event_start_date, i created a shortcode and everything is displaying fine except for it displaying in order, it seems as its not ...
0
votes
1answer
522 views

WP User Query with meta queries

I'm having some problems when comparing integer values '>=' or '<=' with meta_queries with the WP_USER_QUERY. Let say I've stored the following meta keys with the meta values below: meta_key ...
0
votes
1answer
16 views

ACF meta_key and meta_value break loop

I have a CPT with post type of 'recipe'. I have several ACF Advanced Custom Fields in the CPT. My loop WORKS correctly when it is written like this: <?php // args $args = array( 'numberposts'...
0
votes
2answers
625 views

Conditional posts in WP_query for search

I have a custom post type that im trying to limit results in search. The CPT is a deal/coupon, with a start and end date for each of the deals. What I'm trying to do is only show these posts in ...
0
votes
1answer
10 views

Restrict WordPress search to a single ACF field

I've used the following filter to include an ACF field into my search results. add_filter( 'pre_get_posts', 'so_9224493_adjust_search_query'); function so_9224493_adjust_search_query( $query ) { ...
0
votes
1answer
747 views

Is it possible to add relation between meta_query and tax_query?

I have custom post type with some ACF fields. I use ACF for extra properties of entity, and I use native wordpress taxonomies too for base category of entity. So I need to build query with meta_query ...
2
votes
1answer
91 views

WordPress query through Products variation stock [closed]

I have WooCommerce variable products and a filter which is filtering products based on variation attributes. I have variation attribute depth which has numeric value (from 1 to 20) and the filter is ...
0
votes
2answers
58 views

meta query multiple values for the same key

I'm trying to query wordpress with multiple values but it looks like it can't take no more than 4 keywords I'm currently using a loop and I already tried to switch to a IN operator but I need the ...
1
vote
1answer
672 views

How to create a meta_query to get all posts with a specific meta data?

Here are the args for my query : $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' =>...
0
votes
1answer
669 views

How to do meta_query for attachments?

How do I do proper meta_query for attachments? This doesn't show any results $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png', ...
0
votes
1answer
440 views

Used with meta_query in query_posts works slowly

Hey i have a problem this my code and if i used with all parameters i get from $_GET its start work so slowly..... (like 5 min). $checkbox = array( 'immediate'=>'כניסה מידית', 'air'=>'...
0
votes
1answer
12 views

How to use germ_terms() with meta_query for ACF Taxonomy field?

I have a custom taxonomy, Events (“event”). Through ACF, this also has a Taxonomy field, “Topic”, linking it to a secondary taxonomy, Topic (“topic”). I want to get_terms() for all Events terms ...
0
votes
1answer
617 views

How do I add an item to the WP admin menu?

I want to add an item to my WordPress admin menu - "News" - it's to contain a list of articles written about my company. Each article will consist of the following metadata: Headline Date Link to ...
0
votes
1answer
588 views

Search using specific meta fields only (excluding post title and content)

I have a custom post type my_cpt with 9 custom meta fields like first_name, last_name, location, phone, email etc along with post title and post content. Now what I want is to search using first_name ...
0
votes
1answer
21 views

Unusual high query of user meta data

We have a WordPress installation with many plugins installed. The site is not that highly frequented (maybe 10-20 concurrent users). I know the amount of plugins comes at a cost of performance. ...
0
votes
1answer
622 views

Selecting posts older than the current Unix epoch timestamp

I am trying to perform the following query, which originates by the fact the post's 'date' and 'time' are entered as separate custom fields. $args = array( 'post_type' => 'some_kind_of_posts'...
0
votes
1answer
26 views

Query string form $_GET['value'] is not working as meta value in wp_query

Here is my code.How strange! if I put any static value replacing $s_string, it's working fine. Thanks in advance for any help. $s_string = !empty($_GET['q']) ? sanitize_text_field($_GET['q']) : ''; $...
0
votes
1answer
859 views

Order Posts by meta value AND published date

I want to order WP posts by meta key named "sort_date" and if it doesn't exist it should use the post's published date to order posts. Below is the code i am currently using function ...
1
vote
1answer
6k views

How to create/modfiy WP_Query to search in post title OR custom field?

I need to modify or create a WP_Query that will search for a search term in both the post title OR a custom field (called 'my_field'). I have been reading and trying for hours, but I am right back to ...
3
votes
1answer
1k views

How to update single value in multi dimensional Post Meta?

There are some values in Post Meta Data stored as a multi dimensional array. I want to update some of their data. Here is the Post Meta value displayed using <?php the_meta(); ?> voter: a:1:{s:...
2
votes
2answers
99 views

Query WooCommerce orders where meta data does not exist

I'm trying to fetch all my WooCommerce orders where some additional metadata is equal to not empty. $orders = wc_get_orders( array( 'orderby' => 'date', 'order' => 'DESC', '...
0
votes
2answers
1k views

Meta query for comparing two dates

I want to list all users who registered in between the $start_date and $end_date.I have written a metaquery,but it returns empty.Please help. $start_date = 2014-08-16 09:28:17 $end_date ...
2
votes
2answers
48 views

Meta-value query

A little long-winded but trying to explain clearly :) I am delving into the code of my new theme and am not familiar with this type of data storing/pulling - can someone help me understand what is ...
2
votes
1answer
463 views

Working Bootstrap Carousel Conversion to WP - Technical Questions

I have coded a working Bootstrap carousel, it needs to be converted to WP. It's a small chunk of the site, but as a Wordpress newbie, am stuck in understanding the technical issue. So here's what I ...
0
votes
1answer
1k views

Meta query with JSON value

Im using post meta to store some value. Im having the following in wp_postmeta table: meta_key mykey meta_value a:2:{i:0;s:1:"5";i:1;s:1:"2";} I need to return posts which have meta_value of 2. ...
1
vote
1answer
200 views

Filter WooCommerce Orders query with user meta data

I want to list orders from my Woocommerce shop. I have user meta for my users. (unsubscribed) I only want to list the order if that order's user is unsubscribed === 0. I have working code to the ...
2
votes
2answers
1k views

How to display custom field on homepage

I am new to custom fields thing. I am working on a movie review site. And wants to add movie story or plot field, I have successfully added the custom field named Story and its content is displaying ...
2
votes
2answers
149 views

Meta query interfering with orderby relevance

I'm trying to re-order the search results using the pre_get_posts hook and set the orderby parameter to relevance. I also want to put priority posts, which is based on post meta _prioritize_s to be ...
23
votes
9answers
51k views

Using meta query ('meta_query') with a search query ('s')

Trying to build a search that not only searches the defaults (title, content etc) but also a specific custom field. My current query: $args = array( 'post_type' => 'post', 's' => $query, ...
1
vote
2answers
69 views

Comparing between a negative and positive number

I'm having some difficulty comparing between a negative and positive number. This code works fine when it's between two positive numbers but not when it's between a negative then a positive one. This ...
2
votes
2answers
4k views

Displaying Metabox value (custom post type taxonomy)

I have been stuck on this for days, reading articles and articles and nothing works. I am trying to display the value of my metabox on a template page. I successfully added the metabox, and I see ...
1
vote
0answers
20 views

Meta query: How do I return posts within a date period from a given month?

I have posts with a meta start_date and a meta end_date, stored in timestamp format (I can change the format if necessary) I would like to return all posts that have a date in that month by giving a ...
1
vote
1answer
1k views

Get posts with multiple meta values

I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array(...
0
votes
1answer
2k views

Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check ...