Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
16 views

How to order product for key exists?

I'm trying to order the woocommerce products by the existence of a specific meta key, in particular: I need to display first the products that have this meta key, and the all the products that doesn't ...
sfarzoso's user avatar
0 votes
0 answers
32 views

Admin products page column not sorting

I import products to my woocommerce site, and all the imported products have an category called "external". Note: All the external products have a "_ei_product" meta key with an &...
Sidney Sousa's user avatar
1 vote
0 answers
27 views

How can meta values from another site in a multisite be used in a custom query?

Currently, I am using the pre_get_posts action to create a custom query, ordering the posts based on a meta value like so: add_action( 'pre_get_posts', 'my_custom_order' ); function my_custom_order( $...
Jens Draser-Schieb's user avatar
0 votes
2 answers
79 views

Meta query array - same order as specified order in value

I have a custom Wordpress query that is using an array of product IDs that exist in an ACF field(these IDs do not line up with the Wordpress post IDs). I would like for the order of the returned posts ...
user19103974's user avatar
1 vote
1 answer
787 views

Display post in order of ACF checkbox?

I have a custom post type called ‘Skateboards’. Within the custom post type of ‘Skateboards’ , I added three checkboxes (filed type checkbox) with a field name of ‘skateboard_performance’ associated ...
jonTronics's user avatar
0 votes
1 answer
172 views

last_name + first_name orderby with meta_query [solved]

I have small issue with orderby. I´m looking solution to orderby ASC (lastname + firstname) example: Selanne Andy Selanne Beeny Selanne Teemu But now it arrays something like this: Selanne Beeny ...
MSI's user avatar
  • 3
0 votes
1 answer
36 views

Order resultset by configured value and then list all the rest

I want to list jobs (jobs are custom post types) in country order. The country to prioritise in the resultset is defined by the user in the WP CMS. With the configured country being listed first I ...
MarkW's user avatar
  • 3
1 vote
2 answers
1k views

What's wrong with this meta query? (order by meta key, then title, doesn't work)

Here's my meta query: $taxonomy_term = 1494; $args['meta_query'] = array( 'relation' => 'OR', 'mp_exists' => array( 'key' => 'tdlrm_mp_'.$taxonomy_term, ...
Artem's user avatar
  • 315
1 vote
1 answer
2k views

Order by nested named meta queries with 'exists' and 'not exists'

Each of my posts (online store items) has meta keys: tdlrm_mp - my own menu_position (goes from 1 up and, unlike the wp_posts menu_position, may not exist) 1C_quantity_total - number of items in ...
Artem's user avatar
  • 315
0 votes
1 answer
3k views

Sort products by Sale price and stock status

I want to sort products by sale price and in stock and regular price at first but doesn't find solution anywhere. Here is what I have implemented and didn't get the solution: add_filter( '...
vahid sabet's user avatar
1 vote
0 answers
75 views

How to orderby multiple meta fields if some fields are empty

I'm trying to orderby meta fields value, but sometimes those values are empty : A > title = 'The apartment', wpcf-f-french-operating-title = ' ', wpcf-f-order-title = 'Apartment' B > title = '...
Wilhem's user avatar
  • 11
0 votes
1 answer
197 views

Ordering posts by anniversary using only day and month

I defined a custom field named crimedate using standard date format Y-m-d. I defined the filters to make ordering by this date work in the post list of the backend, which works fine. Now I need the ...
geraldo's user avatar
  • 145
0 votes
1 answer
412 views

Ordering posts by custom field named "date" in backend

I defined a custom field named "date" and now want to order the post list in the backend by this field. I defined the filters to make ordering work and header is clickable and shows the ...
geraldo's user avatar
  • 145
2 votes
1 answer
591 views

Order WP Query posts by custom order calculated from post meta values

I am using wordpress REST API to query the database. For each product (a custom post) I have a meta which is product_price at a certain currency currency_rate. I need to run a query to get all ...
houssameddin's user avatar
0 votes
1 answer
232 views

WordPress Query custom ordering by temporary variable

I have created location proximity functionality. I have a WP_Query loop created for a custom post type called Instructor. Each instructor has an address, so if someone enters a zip code it calculates ...
user avatar
1 vote
1 answer
2k views

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures, and Slides. The home page consists ...
jakesh_of_redesigned's user avatar
0 votes
0 answers
61 views

Orderby if between two meta fields

I am trying to orderby my CPT if the current time is in between two meta fields. (i.e, the current_time() is between two time fields.). meta_query returns only the posts that are between the values, ...
Abhik's user avatar
  • 2,921
0 votes
0 answers
107 views

meta_query check multiple date formats

I am trying to query a custom post type that has a meta value (DATE) that are equal or greater than today. My issue is that some posts have the date stored in the "Ymd" format and others have "Y-m-dTg:...
user3686263's user avatar
0 votes
1 answer
50 views

WP_Query of custom post type sorted by meta_key has unexpected results

I do not understand why my code outputs the events in a seemingly random order. It's not sorting by the start_time as I would expect. <?php $args = array( 'post_type' => '...
Mitchell Bennett's user avatar
0 votes
0 answers
73 views

Meta query orderby meta_value_num sorting by role first

I want all of the results to order by meta_value_num, but it's ordering by role first. How do I get them to ignore the role order? Here's my code: $user_query = new WP_User_Query( array( '...
Michael's user avatar
  • 281
0 votes
0 answers
173 views

WP_User_Query Orderby Not Working

If I use the following code, I can retrieve users in the correct order: $user_query = new WP_User_Query( array( 'role__in' => wp_parse_list( $atts['userrole'] ), 'meta_query' => ...
Michael's user avatar
  • 281
1 vote
0 answers
23 views

How to do WP_Query with two meta fields with orderby clause

The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is the query I did so far, but its not working. $args = array( 'post_type' =&...
user8721352's user avatar
0 votes
0 answers
156 views

Multiple orderby date arguments

I've had good luck with using multiple orderby arguments in the past, but now that I'm trying it with dates I'm wondering if there's something I'm missing. I'm trying to order some posts by an ACF ...
zfors's user avatar
  • 169
3 votes
2 answers
4k 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 ...
RachieVee's user avatar
  • 830
0 votes
0 answers
44 views

meta_query orderby sort multiple keys

I'm trying to read the birthdays of the users in my database through custom fields that have been added. Displaying the current months is easy but I am trying to capture the current month(remainder) ...
user3692010's user avatar
0 votes
0 answers
117 views

Sorting with meta_query and multiple, optional meta keys

I'm trying to sort a custom post type by 3 properties: Meta Key: is_featured Meta Key: is_primary Title The two keys are boolean ACF items, and are both optional, so most of the posts don't have the ...
ken.dunnington's user avatar
0 votes
0 answers
153 views

Why does this incorrect pre_get_posts meta_query work for sort order?

I've got a fairly complicated post type archive page that I need to order by two meta fields and the post title. To do that, I'm using pre_get_posts with a meta_query that simply tests for the ...
mrwweb's user avatar
  • 10.3k
0 votes
0 answers
81 views

WP Query. Ordering posts by another post types meta

I have a custom post type called BID which contains a users bid (similar to freelancer.com, upwork, etc) However I need the BID results on the page to be ordered by meta stored in a users profile, ...
Miguel Dey's user avatar
2 votes
1 answer
3k views

Display custom post types with custom date field value (before today) & order by custom date field

I'm trying to display custom post types with custom date field value being before today. It works OK for showing posts before today, but the order is only based on post date. I want to have the result ...
guiyom84's user avatar
2 votes
1 answer
3k 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 ...
Ehsan's user avatar
  • 23
-1 votes
2 answers
799 views

wp_query sorting – one specific meta_key value at last and then sort by create date

I'm having a custom post type "products" of which I need to show a list. The products are sorted by meta value into different kinds of product type. I need to set one specific product type "tools" at ...
HHGK's user avatar
  • 39
1 vote
1 answer
83 views

WP_Query ordered by meta_value_num doesn't fetch posts without this meta field

I have a custom user query, which should order users by a custom meta field staff_profile_position. Users, who don't have a staff_profile_position are not fetched with this query: $args = array( '...
Bunjip's user avatar
  • 371
4 votes
2 answers
8k views

WP REST API: Order posts by meta value (acf)?

I'm requesting posts with the WP REST API and need to sort them according to an ACF field. It's value represents a date (numeric, jQuery date format yymmdd). I know how to do it with a normal WP_Query ...
Mauro Bringolf's user avatar
1 vote
1 answer
455 views

SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)

Hey there I have the following SQL Query which is generated by WP_Query numeric meta query: SELECT SQL_CALC_FOUND_ROWS wp_postmeta.meta_value FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = ...
Blackbam's user avatar
  • 565
1 vote
1 answer
339 views

Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?

This are my current parameters for WP_Query: array(5) { ["posts_per_page"]=> int(6) ["orderby"]=> array(2) { ["uss_product_price"]=> string(3) "ASC" ["uss_product_weight"]...
Blackbam's user avatar
  • 565
1 vote
1 answer
584 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=...
gishua's user avatar
  • 11
2 votes
1 answer
2k views

Sorting posts by multiple values, combined

In this image, 1. The Black letters are default post titles 2. The number before the 'of' is a custom field. 3. The number after the year is the post's published year Now I want to sort this ...
Murshid Ahmed's user avatar
1 vote
0 answers
157 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(...
rob-gordon's user avatar
1 vote
0 answers
35 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 ...
Augus's user avatar
  • 131
0 votes
0 answers
1k views

Best way to Order Post in Home without a plugin

We are trying to reorder one section of the home page. our approach was with meta_keys and meta_values WP_Query Sample: <ul id="featuredMain" class="feautrued-main"> <!-- Main ...
Locke's user avatar
  • 185
0 votes
1 answer
185 views

Query Posts that have or don't have a meta_value and order by the same ASC

I'm trying to perform a scheduled update to all posts, 10 posts at time. To achieve this, I run Cron job with a script that saves 2 post meta: $DATA: the data I want to be update $TIME: the UNIX ...
bluantinoo's user avatar
10 votes
2 answers
27k views

ORDER BY custom field value

Based on example here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/ I'd like to modify the query $q = new WP_Query( array( 'meta_query' => array( ...
dkatwp's user avatar
  • 217
0 votes
1 answer
1k views

ORDER BY custom field value out of where clause

Based on example here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/ I'd like to modify the query $q = new WP_Query( array( 'meta_query' => array(...
dkatwp's user avatar
  • 217
1 vote
1 answer
2k views

Sorting posts by custom fields in meta_query

How to apply 'order_by' in WordPress query in the following example: I have a query to get all posts with custom field for event dates greater or equal current date. I can have up to 10 event dates (...
dkatwp's user avatar
  • 217
1 vote
1 answer
2k views

pre_get_posts order by not working

I am using the pre_get_posts hook to alter a query before it runs. The posts in question are performances and so are date and time based. I want to alter the query to get all performances which are ...
Michael's user avatar
  • 305
2 votes
2 answers
31k views

Advanced WP_Query with meta_query, orderby?

I wonder if anyone can help me with this little complex query with ACF. I have the following so far which should display: Pages, News Articles, About Articles and Involved Articles. Show: only 4....
user4630's user avatar
  • 245
2 votes
2 answers
3k views

List of posts by day of the week

I have Radio with programs and they are associated to day of the weak. Example: 1-Program Disco Nights plays at Monday and Friday 2-Pragram Crazy weekends play only at Sunday 3-etc 4-etc ...
Rodrigo Borba's user avatar
1 vote
0 answers
727 views

meta_value_num not ordering all items

I am using meta_value_num to output a list of items in order by a custom field. The custom field value that is being passed is 1, 2 ,3 or 4. The order works for the first 7 items but after that they ...
alexmattorr's user avatar
2 votes
0 answers
734 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 ...
Shyam Krishna Sreekumar's user avatar
0 votes
2 answers
235 views

Orderby doesn't work like expected on custom query

I have this custom query: query_posts( array ( 'orderby' => 'rr_recommends_count', 'meta_key' => 'rr_recommends_count', 'order' => 'DESC', ) ); Which orders the posts ...
Klevis Miho's user avatar