The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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.

282 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
3k views

Add indexing to meta_value in wp_postmeta

Is it poossible to add index to the meta_value column in the wp_postmeta table in order to make faster queries in Wordpress? I have about 5 million rows in the wp_postmeta table and my queries takes ...
3
votes
1answer
315 views

Custom Queries: Joining On Meta Values From Two Custom Post Types

Hi – I'm hoping this is the right place to be asking this question. I am in the process of moving my full football club website onto Wordpress, therefore using a single database for the information ...
3
votes
0answers
5k views

Custom Upcoming Events List for Events Manager Plugin

I'm using Events Manager plugin. I want to list upcoming events without widget. (2 event with big thumbnail image, after then 4 event with small thumbnail image.) Tried this code: <?phpfunction ...
2
votes
0answers
55 views

Can an array be used as a meta_query value?

I'm trying to query a custom post type (courses) by grade using WP_Query and Advanced Custom Fields (ACF). Grades (checkboxes) are organized by term (groups). Four grades per term, four terms per ...
2
votes
1answer
539 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 ...
2
votes
1answer
701 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 ...
2
votes
1answer
54 views

Which is best in the following scenario : post_meta vs custom table vs parent/child posts

I’m looking for a bit of advice on which way to go with a development question. I’m building a community site where subscribers create their own private posts. The data they enter falls into two ...
2
votes
0answers
47 views

Multiple meta queries but arrange by specific meta value order

Im working on a function which gets me lawyers based on criteria. The function works fine. Recently I added a meta key called 'is_endorsed'. The value can be either '1' or '0'. I need to bring ...
2
votes
1answer
65 views

meta_query all posts between to ages

I'm trying to query posts for a specific age range. For example I have a post with an age range from 5 - 10. If I use the following code I get a result when I search for ages >= 5 and 10: $meta_query ...
2
votes
0answers
41 views

WP_Meta_Query causing long-running MySQL queries

I used the following WP_Meta_Query which queried posts for a specific custom fields pair. $args=array( 'meta_key'=> 'tnid_01', 'meta_value'=>$tnid, '...
2
votes
0answers
480 views

How to make a WP REST API query with meta_query in WP4.7?

There is no "filter" parameter in WP REST API WP 4.7 and this call doesn't work: http://domain.tld/wp-json/wp/v2/cpt_name?meta_query[0][key]=cf_name&meta_query[0][value][0]=cf_value1&...
2
votes
1answer
508 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 ...
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
0answers
714 views

sort by date in Advanced Custom Field

I am trying to filter posts with certain values and sort by the date field using ACF module. I have succeeded in filter with package and type. But when i added date sort, its not working. Please help ...
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 ...
2
votes
1answer
43 views

wordpress custom_meta ordering of timestamps

So I have a wp meta query that is handling the searching of events which have a start timestamp, and an end timestamp, I want to return all results within the two dates a user picks in the search. ...
2
votes
1answer
196 views

XOR functionality for meta_query

I'm trying to resolve the problem with event displaying. An event has its start and end dates, written in meta. For example, event starts on (dmY) 03.04.2013 and ends up on 08.04.2013. Using WP_query ...
2
votes
1answer
1k views

Very slow query with meta_query on large database

I have a blog with about 200k posts and each one have 20 custom fields. I've been using WordPress Transients_API to cache queries, in the few cases where it can be used, but it can't be used in some ...
2
votes
2answers
330 views

CPT Meta Searching

I'm developing a WP plugin which uses custom post types and meta data. What I'm trying to achieve is having the meta data searchable. Here is some code that I found which searches the meta data fine, ...
1
vote
1answer
14 views

Stuck in Order by more then one

I want to orderby post by 2 custom fields and alphabetical here is my code 'meta_query' => array( array( 'relation' => 'AND', 'awards' => array( 'key' ...
1
vote
0answers
43 views

Meta query with regular expression does not work

I am trying to get a meta query with a regular expression to work. I have a custom post type with a custom field "participant-id". The custom field stores a comma-delimited string of user IDs, like:...
1
vote
0answers
14 views

Searching in title or meta, with a tax query too!

As suggested in WP Query Args - Title or Meta Value I tried to query my Custom Content Type on Title and Meta Value alternatively. It almost works, but only if I do not introduce a tax query (and I ...
1
vote
0answers
22 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
0answers
40 views

Tax Query for custom Taxonomy field

I have a stock filter on WooCommerce shop page. So I need to filter number of products based on the selection from the user for this filter. I have variable products and I am not able to control ...
1
vote
0answers
16 views

Meta Query Not Returning Output Despite Having Matching Values

I am formulating a query to pull from a custom post type, with values matching a custom field. The results are blank although I have 3 values set matching the custom field. Is my query formulated ...
1
vote
0answers
116 views

Extend product search with meta in WooCommerce

I would improve the search bar in order to exploit manufacture attribute linked to product. I try to use this to filter product by a custom meta (no product attribute) function custom_search_query( $...
1
vote
0answers
55 views

How does one perform a sub query with different post types

I am creating an application for a home cleaning service using the WP API. I have two custom post types called property and job. The property posts contain a list of home addresses and phone numbers....
1
vote
1answer
114 views

WP_Query with meta_query no results

I have a custom post type and can get them using WP_Query with the following array: $args = array( 'post_type' => 'projects', 'post_status' => 'publish', 'posts_per_page' ...
1
vote
1answer
32 views

How to orderby multiple meta fields with another meta query

I have a custom post type ”events” with meta fields ”startdate” and ”enddate”. Archive query already uses meta query to show only upcoming or ongoing events, but in addition I need to order by both ...
1
vote
0answers
113 views

How to show recent and upcoming birthdays using meta_query

I have a date of birth user field, I am trying to show recent (past 7 days) and upcoming (next 7 days) birthdays. I have the below but it is not working because the years in the date of births are ...
1
vote
0answers
133 views

How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?

I'm trying to include post meta in the scope of a WordPress search using WP_Query. I have a meta query that looks like this: $args['meta_query'] = [ 'relation' => 'AND', [ 'key' =...
1
vote
1answer
30 views

how to make members list directory through wordpress post custom meta key.

I have created a website in which I am providing complete information about the organization. For this, I am using a Wordpress post. In which I am putting information of only one organization in a ...
1
vote
0answers
72 views

Why is this query not working? (Standard posts + custom post type)

I'm trying to figure out why this query is not working, as it seems like it should be very straightforward. Basically, I'm querying for both standard posts of certain categories (and excluding another)...
1
vote
0answers
501 views

Using meta_query and tax_query at the same time

I’ve got the following query on my page template: $args = array( 'post_type' => 'givingback', 'post_status' => 'publish', 'posts_per_page' => 100, '...
1
vote
1answer
575 views

WP_Query: include custom post type only with specific meta value

I have the following arguments for a WP_Query: $args = array( 'post_type' => array( 'cpt-1', 'cpt-2' ), 'post_status' => 'publish', 'posts_per_page' => 9, 'meta_query' => ...
1
vote
0answers
66 views

Modify wp-query and sort by post meta key

I am trying to modify a query, but can not figure out how to sort the results by post meta and then randomize the results. The key I am sorting by has 6 possible values: gold, silver, bronze, copper,...
1
vote
1answer
731 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' =>...
1
vote
0answers
1k views

Filtering variable WooCommerce products by stock level using meta_query

I'm trying to filter the products on my shop page based on stock level by adding a condition to the meta query. For variable products I get zero results, but simple products work. I'm running the ...
1
vote
0answers
154 views

Filter posts by advanced custom field

How I can create filter which will filter posts by one custom field - year? Field name: year Field type: number I need to setup some dropdown in page with existing values. For example in 3 posts I'...
1
vote
0answers
129 views

Changing sort order for presentation by Jetpack infinite scroll

I have been able to use WordPress filters for posts_join_paged, posts_where, and posts_orderby to create a query that presents a set of artists where only artists who have a last name listed in the ...
1
vote
2answers
95 views

Large AND OR query timing out

I am working on a wordpress calendar plugin and ran into a issue with custom fields. I can do two separate queries one for repeat events and one for static events but when I try to combine them my ...
1
vote
0answers
17 views

Orderby listing issue

I installed the Post Expirator plugin in order to automatically classify active and expired post. I have to display the group of active post ordered by data and then the expired post ordered by date. ...
1
vote
0answers
113 views

search suggest - filter post type

I'm using "Instant Search & Suggest" wordpress plugin. Let me give an example so it will be clear. So let's suppose that I have 2 custom post types: products and suppliers. For example, when I'm ...
1
vote
1answer
258 views

Help ordering Post loop by two meta values

Background: I have a custom post type "events" which has a post meta value of a unix timestamp called event start date. I also have a post meta value of ticket_status that has 3 possible values (S=...
1
vote
0answers
145 views

Order ascending is ignored in meta query?

I'm using pre_get_posts to alter my main query and attach a meta query to it. This is on a woocommerce products archive page (...not sure if that would make a difference). function has_upcoming_date(...
1
vote
0answers
31 views

Alter main archive, to show posts with meta as last

I'm having troubles with getting posts with meta_value "sold" as last in the main query of my custom Post type. The best/easiest way i can think of at the moment is to filter the "sold" posts out of ...
1
vote
1answer
169 views

Custom query, checking values of multiple meta keys

I am using two plugins, and I have some issues combining them. One is an event calendar, which add new meta keys to posts, the other is a show-posts-as-grid plugin, that fetches the event posts from ...
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(...
1
vote
1answer
155 views

WP_Query with different postmeta filter for each categories

Let's say I have categories (cat1, cat2) and I have postmeta keys (date1, date2, status). How do I view all posts in all categories with these filters: For cat1, I want to apply WHERE date2 <= $...
1
vote
0answers
69 views

Meta Query posts not showing on ending date of custom field

I feel like my logic is off, but the short version is I have 2 custom fields spitting out unformated times for event-start-date and event-end-date. I don't want to show a post if the start-date is not ...