Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sort]

The tag has no usage guidance.

2
votes
1answer
94 views

Sortable admin column for one meta key with three possible meta values

I've looked over 2 or 3 similar looking threads regarding sortable columns and the meta queries involved with making them work. None seem to resolve my exact problem. I am using the pre_get_posts ...
1
vote
0answers
21 views

Understanding the orderby in WP_Query?

For quite a while I have been trying to query posts, with 2 different meta_queries, and order them differently. I followed the WP codex. Recently I have found out that I have been mistaken this ...
0
votes
0answers
32 views

Order 2 meta_queries differently in WP_Query?

I have a custom WP_Query with 2 different meta queries. I want to order the results of both queries differently. The first meta_query I want to order by a custom field (high integer - low integer). ...
1
vote
1answer
25 views

Custom post type, organized by categories

I know there are lots of questions and answers out there for this very thing, but I'm having a hard time putting it all together. The goal is to get a <ul> with category names as the <li>, ...
0
votes
0answers
32 views

How to sort wordpress posts by distance and date

I want to sort wordpress posts by user's distance from posts location and by date by using some calculation..Here is the formula. 2*log(distance) - log(time in seconds) I saved post's latitude and ...
0
votes
0answers
23 views

How to use multiple orderby conditions on query search results? (orderby one post type, relevance)

I have a need to sort the search results so that a custom post type "authors" is always at the top, followed by all other post types sorted by relevance. I've found numerous examples about altering ...
0
votes
0answers
10 views

Need a Plugin for Sorting Specific Category Posts within a Static Page

I am NOT a strong PHP coder and mainly create sites using plugins and custom CSS which I am strong at. I have a page listing posts from a specific category. The page is built using Elementor Page ...
0
votes
0answers
85 views

woocommerce product sorting based on custom fields

I am trying to add a custom sorting option for woo commerce . So I am using following code to add new sort option plus set it as default meta key is '_am_cat_sort' function ...
0
votes
2answers
22 views

Sorting post by custom field and category

I want to sort posts by a meta value in a custom field. Basically I've added a field called 'date_event' and want to sort the posts by that date (stored as YYYYMMMDD). The only working example I have ...
0
votes
1answer
26 views

Wp Query sort order from custom MetaBox

I am trying to sort a list of post based of the meta_key deal amount, which would be to display the highest deal first and work its way down to smaller deal amounts. The deal amount would be anywhere ...
0
votes
2answers
44 views

Case insensitive ORDERBY in wpquery

I'm trying to sort custom posts in alphabetical order, and I've just now realized that capital letters are being sorted before lowercase. Two restaurants start with 'Cal' and 'CAT' with 'CAT' being ...
0
votes
2answers
119 views

Woocommerce Category Sort Dropdown

In Woocommerce Category page default sort dropdown has like below options. My question is what/how products sort by Popularity ? Not a code What is the measurement ? like if sort Price: Low to High,...
0
votes
1answer
90 views

Sort by last word in title

I need to order posts within a category alphabetically based on the last word in the title. I have seen a few suggestions online but none fit correctly. I am using a custom layout for the category ...
0
votes
0answers
42 views

Sort posts on custom field AND after that sort on date?

I'm having trouble to understand customizing the new WP_query. I've found the script below, partly, here in order to get the sticky posts. I've further edited it in order to: first get the (sticky) ...
0
votes
2answers
55 views

Orderby Title not working

When I'm trying to sort my blog posts or my woocommerce in alphabetical order nothing changes. If I access the /?orderby=title-asc or ?orderby=title-desc it brings me the same results. Any sugestions?...
0
votes
1answer
21 views

How to mix two orderby-parameters into one ordered result

I'm trying to figure out how to get an alphabetically ordered list of posts using two different orderby parameters. Im filtering the archive query something like this: function ...
0
votes
0answers
15 views

Custom Sort Order for looping through Taxonomy

I'm looping through all categories for a custom post type. What I'm trying to do is manually set the order for the loop by taxonomy id: My current format is: $categories = get_terms( '...
1
vote
1answer
169 views

WooCommerce sort products by the actual product width(not the shipping width)

I have regular/simple products and products with variance in the database. Regular products and variations have a product width(_pm_width_inches) associated with them . I am trying to sort based the ...
4
votes
4answers
748 views

WordPress post sorting with AJAX

I am having a search result page for custom post type. I want to have a ajax sorting feature. Eg sort the post by taxonomy without reloading the page. A very basic example will help. Thanks The ...
0
votes
0answers
174 views

Custom sort by menu_order not working when set as Default product sorting

I have products with Gallons as size so I want to list products in ascending order by Gallon size so I added numeric gallon values to the menu_order attribute field. After adding the below code to the ...
0
votes
2answers
498 views

how to get post order by post id wp_query?

i have 4 post and i displaying 2 post per page. $ids = array('16085','16088','16083','16091'); $options = array( 'post_type' => $post_type, 'posts_per_page' => $posts_per_page, ...
0
votes
1answer
209 views

Multiple sorting criteries (order by)

I want my products to be sorted by price (ascending) and products, which are out of stock be placed at the end of the products list. How can I achive this in WooCommerce? Is it ever possible to ...
0
votes
0answers
98 views

Sort admin column based on an acf within a post object

I have a question about sorting admin columns based on an acf, and the 'post_title' within within a post object. I am following this set up here - https://www.ractoon.com/2016/11/wordpress-custom-...
0
votes
1answer
61 views

change order of images attached to post

Im not quite sure how to explain my issue so let me know if Im unclear about anything. I have on my front-end post form a multiple file upload input that uploads files to my specified folder and ...
0
votes
0answers
33 views

WP_Query order_by custom meta with advanced query

So I am trying to WP_Query all post type of "triextras" There are 2 types of "triextras" categorised by taxonomy: news (id:22) and events (id:21) Events has custom field event_date. When I query ...
0
votes
0answers
225 views

Column sorting for taxonomy table using Advanced Custom Fields

I'm trying to get my admin columns on edit-tags.php to be sortable by ACF field value, but I'm missing something. I can click the column heading to sort the column, but it only sorts the table by tag ...
0
votes
0answers
17 views

How to sort posts by 1-5 star rating selected by the user?

How to get than after a user clicks 5 stars I get that info and use it to sort posts who have a 5 star rating. <form action=""> <img class="ylli-1" src="img/icons8-christmas-star.svg" alt=""&...
0
votes
1answer
22 views

sort items by randomness

I have an e-commerce shop. I am new to php and wordpress. (I have a python and ruby background though, I just don't know php) And I have a page with items. Right now the last 20 items are displayed ...
0
votes
0answers
22 views

Problem with displaying products

I've got problem with my WC store. When I go in unregistered mode to category page, there are display just a few product (sorted by popularity). When I change sorting, after that are displayed all ...
0
votes
0answers
84 views

WP_query sorting can't sort danish letters (æ, ø, å)

I am having an issue, with making a WP query sort correctly, using danish special letters (æ, ø and å in this case). I have a loop running a query for certain post types, then returning them ...
0
votes
0answers
64 views

How to sort custom posts including null meta-values ​in admin columns with meta_query?

SQL REQUEST SELECT post.ID, month.meta_value, year.meta_value FROM wp_posts post LEFT OUTER JOIN wp_postmeta month ON month.post_id= post.ID AND month.meta_key='mcv_end_month' LEFT OUTER JOIN ...
0
votes
0answers
20 views

sort by custom field in taxonomy page

I want to sort posts by a custom field and applied following code. It works on the archive pages, but it doesn't work on the taxonomy pages. The codes for archive and taxonomy are same, i.e., "archive-...
0
votes
1answer
29 views

Using Orderby and meta_value to order natural/alphanumerical

I added a custom column for a custom post type. Then I put it to be the 3th column, and now I want to sort it alphanumerical. I use this action : add_action( 'pre_get_posts', '...
0
votes
0answers
27 views

Ajax sorting not show correct result?

i am working my website . when i am trying to sort the listings using sort options it is not showing correctly. i am attaching the following image in which i mention that if i select sale & rental ...
0
votes
0answers
36 views

Sort by custom field in archive.php with Ajax

how can I sort custom post types by custom field value with ajax. There should be options "Newest" and "Oldest".
0
votes
0answers
28 views

How to order blog posts by no. of likes?

I am using a plugin called Kodex likes and it has a counter for how many likes a blog post got. If I add sorting parameters to the URL using the ones already built in Wordpress like: www.website.com/...
0
votes
0answers
84 views

Sort by Featured products, shows some which are not

I’ve added the code below to my functions.php to make it possible to ‘sort by featured’. Although, some items do show up which are not marked as featured. I can’t figure out why the keep showing op ...
0
votes
0answers
45 views

Order posts by specific post IDs

I have the following code: $viewed_products = [3358, 3296, 3929, 3368]; $query_args = array( 'posts_per_page' => 4, 'no_found_rows' => 1, 'post_status' => 'publish', '...
1
vote
0answers
26 views

WP Query sort by meta value

I would like to get posts order by timestamps. I have to following code but the query keeps getting posts order by modification dates and not with the "evcal_srow" meta. Any clue? <ul class="...
0
votes
0answers
193 views

Sort order using get_the_terms() for multiple taxonomies

I'm using get_the_terms() to echo the term names of multiple taxonomies by passing an array of taxonomy slugs, as follows: $terms = get_the_terms( get_the_ID(), array('tax-1-slug', 'tax-2-slug') ); ...
4
votes
1answer
132 views

How to Arrange Posts by Size in the WordPress Dashboard?

This may be a lame question, but I can't find an answer to this. Let's say you have a ton of empty posts that you want to delete. Obviously those who have some content will have more size. Is there ...
0
votes
1answer
1k views

Custom post type sorting: alphabetical order

I want to display my custom post type "portfolio" in alphabetical order and I got it working fine with this code: add_filter("posts_orderby", "my_orderby_filter", 10, 2); function my_orderby_filter($...
0
votes
1answer
1k views

Sorting search results with custom dropdown

I have the following select dropdown code for sorting on my search results page (search.php) that works for custom fields. <div id="sortby"> SORT BY: &nbsp; <select class="dropdown-...
0
votes
1answer
18 views

Sort posts by clicks on download button

In my website each post has a download button for a certain asset. I want to be able to sort my posts by how many times an asset has been downloaded (or, in other words, how many times the download ...
0
votes
0answers
20 views

sort options for search results

I have a search for specific categories posts, the category is called archive, and am wondering if after they are displayed they can be sorted by either most recent or most relevant via a dropdown. ...
0
votes
0answers
25 views

How sort posts by average daily vews?

I'm creating a plugin that inserts a widget in the sidebar, it sorts the posts by comments, total views and average daily views, For the count views i do with this functions: //get posts views ...
0
votes
1answer
23 views

sorting in wp query based on custom field value

I am trying to get posts of custom post type 'job_listing' on bases of two custom fields i.e 1) _job_location 2) _company_name this is working fine but I also want to display the posts first that ...
0
votes
1answer
636 views

Order woocommerce products alphabetically by second word in title?

My site actually has people's names as product titles and I really need it to sort alphabetically by the second name (surname) I think I've found solutions to enable this with default WP post titles ...
2
votes
2answers
518 views

Make custom column sortable

I have added custom column to a custom post type, and it works fine. I just want it to sore the names by title so tried this, function sortable_custom_columns( $columns ) { $columns['...
0
votes
2answers
614 views

How to sort (orderby) a query done by a template function before the 'foreach' loop?

How can I sort an array of elements being hold on a query done by a template function, just before the output starts on a foreach loop? I wanted to order my elements by the Post Title. Here is my code:...