Skip to main content
42 votes

Make custom column sortable

Make sure to change MY_POST_TYPE, MY_CUSTOM_COLUMN and MY_META_KEY to the actual values. First, add your custom column. Unset the date and set it again to keep it in the last column. You can skip ...
Max Yudin's user avatar
  • 6,368
9 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Tried to hook in without success. Might be just a problem of my configuration, but for those who can't make the hook work, here is the simplest solution: <?php $all_posts = new WP_Query(array( ...
Zibellino's user avatar
  • 190
7 votes
Accepted

How to Arrange Posts by Size in the WordPress Dashboard?

Sorting by size Adding custom column and sorting by post_content length is possible. It won't be very efficient though, I'm afraid. First you'll have to add your custom column and display the length ...
Krzysiek Dróżdż's user avatar
6 votes
Accepted

How to Group Posts by the First Letter or Number?

I think there's a better approach, just create a custom taxonomy that holds the alphanumeric terms, then assign each post to the correct term. You can use the save post action to auto assign posts to ...
Alex Sancho's user avatar
6 votes
Accepted

Sort in WP_Query(), not filter? Is it possible?

If you want to sort the posts by the meta post_views_count, and still include posts that do not have that meta, you can use meta_query like so: 'meta_query' => array( 'relation' => 'OR', // ...
Sally CJ's user avatar
  • 39.9k
5 votes
Accepted

Sorting search results by taxonomy terms

Unfortunately, although WP_Query supports the 'tax_query' arg, it does not support ordering based on post terms. So you will need to modify the query SQL, as you are doing now. However, you are ...
J.D.'s user avatar
  • 3,945
5 votes

register_post_type sort order by title by default

I found this answer was better here (altered to suit question): function se91124_order_post_type($query) { if($query->is_admin) { if ($query->get('post_type') == 'States') { ...
hazrpg's user avatar
  • 225
5 votes

Filter admin columns by custom post field value

For comparison, I made a post type of dog with both a custom field dog_colour and a taxonomy dog_colour. With both added as admin columns, we get: The taxonomy terms are automatically linked with a ...
Andy Macaulay-Brook's user avatar
4 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

FWIW here’s how you can order by menu_order for a specific custom post type: /** * Customize adjacent post order */ add_filter('get_next_post_sort', function($order) { if (is_singular('...
Ted Whitehead's user avatar
4 votes

Orderby meta_value only returns posts that have existing meta_key

I tried applying @Manny Fleurmond's answer and like @Jake I couldn't get it to work even after correcting the typo that 'orderby' => 'meta_key' should be 'orderby' => 'meta_value'. (And for ...
jlad26's user avatar
  • 51
4 votes
Accepted

Orderby Post Views

You can sort your query by view number, using the meta key : $query = new WP_Query( array( 'meta_key' => 'post_views_count', 'orderby' => '...
Johansson's user avatar
  • 15.4k
4 votes
Accepted

how to get post order by post id wp_query?

OK, so you want to define posts order by yourself. WP_Query allows you to do that - you'll have to use orderby => post__in to achieve it. And that's what you do. So why isn't it working? Because of a ...
Krzysiek Dróżdż's user avatar
4 votes

Filter admin columns by custom post field value

Based on @ Andy Macaulay-Brook comment on your question you can try this (it will add a dropdown next to the Filter button on top of the admin listing table): add_action( 'restrict_manage_posts', '...
Qaisar Feroz's user avatar
  • 2,147
4 votes
Accepted

Display sorting options dropdown when using WooCommerce product category shortcode

Since WooCommerce 3.2, Woocommerce shortcodes and their available attributes have changed. So try the following shortcode instead (for "foo" product category): [product_category limit="90" columns="...
LoicTheAztec's user avatar
  • 3,381
4 votes

Display sorting options dropdown when using WooCommerce product category shortcode

If you would rather want to get the sorting menu using a shortcode then you can create one for it in your functions.php // Creating Shortcode for Product Sorting add_shortcode('wc_sorting','...
Abhishek's user avatar
3 votes
Accepted

Number of pages - multiple (custom) post types

Milo is right, you should be using pre_get_posts instead of calling a 2nd query on load. This will make paging much easier. Whatever the orderby session you're using it should still be accessible in ...
Howdy_McGee's user avatar
  • 20.8k
3 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Based on @Szabolcs Páll's answer I've created this utility class with helper methods to be able to get posts of type by menu order and get the next and previous post by menu order as well. I've ...
Eli Jayson's user avatar
3 votes

Query Set Order By Author

To order by the authors nicename is not nativly supported by the WP_Query. If you order by author, as you have experienced, you order by the ID of the author. So, you would need to actually go into ...
websupporter's user avatar
  • 3,019
3 votes
Accepted

How to sort posts in admin by titles with dd.mm.yyyy format?

It looks like the post titles have the date format DD.MM.YYYY. We can order the DD.MM.YYYY titles as YYYYMMDD with: $query = new WP_Query( [ 'orderby' => 'wpse_mod_title ' ] ); that's supported ...
birgire's user avatar
  • 67.8k
3 votes

list posts and wrap them alphabetically A-Z

I would do it the other way around- loop over the alphabet and check all posts for a match with each letter. $all_posts = new WP_Query( array( 'orderby' => 'title', 'order' =&...
Milo's user avatar
  • 78.8k
3 votes

Sort posts by numeric value of custom field, and also show any other posts without that custom field

In order for sorting by a meta value to work, the meta_key parameter is required (source): Note that a meta_key=keyname must also be present in the query. Unfortunately this will result in only ...
Caleb's user avatar
  • 2,444
2 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Based on @Szabolcs Páll's answer and bbloomer's post on adding next/prev buttons in WooCommerce Single Product Page, I created this code. It sorts all products by meta key and adding prev/next ...
Elron's user avatar
  • 159
2 votes

how to sort post in admin column by recently

add_action( 'pre_get_posts', 'change_post_sort', 1 ); function change_post_sort( $query ) { if ( is_admin() && $query->is_main_query() ) { $query->set( 'order' , '...
MohamadHossein's user avatar
2 votes
Accepted

sort query results by newest

WP_Query(array('post_type'=>'portfolio_item', 'post_status'=>'publish', 'posts_per_page'=>-5, 'order' => 'ASC')); See: https://codex.wordpress.org/Class_Reference/WP_Query#Order_....
Tex0gen's user avatar
  • 572
2 votes
Accepted

Sort a custom post with ACF: Date Picker & Display Featured!

Please change your args like this. $meta_query = array( array( 'key' => 'event_type', 'value' => 'featured', 'compare' => '=' ) ); $args = array( '...
Faysal Mahamud's user avatar
2 votes
Accepted

Function to alphabetically sort custom post types creating duplicates

'orderby' => 'name' sorts by slug - not title; therefore, the title Imancorp Foundation which has this permalink http://www.alianzafpdual.es/las-empresas/fundacion-imancorp-foundation/ breaks the ...
Michael's user avatar
  • 8,409
2 votes

sort search results by custom fields using dropdown

Form will automaticly add your select value to url when you submit form. There is no need to create such a value &orderby=date&order=dsc. If you want to pass multiple information in single ...
kierzniak's user avatar
  • 2,472
2 votes

Make custom column sortable

Make Columns Sortable By default the new custom columns are not sortable so this makes it hard to find data that you need. To sort the custom columns WordPress has another filter manage_edit-...
Abdullah Mahi's user avatar
2 votes
Accepted

Custom post type sorting: alphabetical order

Try using $query->get() instead of get_query_var(). function my_orderby_filter($orderby, &$query){ global $wpdb; //figure out whether you want to change the order if ($query->...
Sally CJ's user avatar
  • 39.9k
2 votes

WooCommerce product sorting VERY slow

Here's a plugin that deals with this fairly effectively. https://github.com/haydenw/woocommerce-product-sorting
GeorgeQ's user avatar
  • 121

Only top scored, non community-wiki answers of a minimum length are eligible