Up Arrow

Order WordPress Posts by Title Using jQuery

  • Date: December 29th, 2016 | by Saniul Ahsan
  • Facebook
  • Tweet
  • Googleplus
  • IN
sort wordpress title using jquery

If you failed to order your post by post title using WordPress query chances are the following jQuery snippet will come in handy.

Suppose you have a div and element like this generated after WordPress query.

Now if you want to manage the links from the WordPress loop and sort them alphabetically by jQuery then give it a try.

I have added a data attribute named “data-order” to the link and added the post title’s first alphabet to the link, the output like this.

Now we will add our jQuery code to the div’s children to make them alphabetically ordered.

Now the question is what the code will do? the code will get the children of the div’s and get the “data-order” attribute value of the link and then compare the value with others until they are sorted alphabetically. Sounds fun, isn’t it?

The output will be something like this.

Hope you will find it helpful. Thanks and I look forward to receiving your thoughts.

Recent Posts