Back to Top

How To Sort by custom fields in WordPress

After the Long time, I come with the quick post that is how we sort data in WordPress by custom field.Today I wanted to sort by a custom field for company name menu in sidebar so its display category alphabetically in ascending order by custom field and it’s too simple to sort post, page or category by custom field in WordPress so let’s take a look!

For that I have used get_posts() function but you can use following code with query_post(),have_post() or any function which is used for loop.

Here, I have passed order by,meta_value and order as the argument in get_posts() function and where “company” is the custom field. It could give me a sorted list of custom field “company” by arranging the meta value of that custom field in ascending order.

That’s it.Now you have records sorted by custom field. 🙂

Also Read:

To create extra field into category or Custom Taxonomy in WordPress
To Create custom field in Woocommerce Products Admin Panel
To Delete Taxonomies from database in WordPress

I hope you have enjoyed this article. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

To parse CSV Data in PHP

Posted on 12 years ago

Bhumi

Getting started with Laravel

Posted on 7 years ago

Bhumi

Getting Started with LESS CSS

Posted on 9 years ago

Bhumi

How to install zend framework on wamp

Posted on 11 years ago

Bhumi