WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have a custom post type (ex. songs) and have a few posts that I created for this post type.

I want to display them on a webpage in order (ex. 1, 2, 3, ...). How do I get the index position and display it on my page?

Any insight or solutions would be greatly appreciated!

share|improve this question
You mean pagination? What exactly do you mean by index position? – Hamed Momeni Sep 19 '12 at 5:27
Are you talking about both changing the order and displaying the index position, or only one of the two? Also, is the index position meant to be a ID/primary key of some kind, or is it determined according to the song's place in the final list? – Barbarrosa Sep 19 '12 at 22:08

One solution is to add a custom field to the posts. Call it index_position or something similar. Create a nice meta_box if you want the client to be happy.

Then, when you query for posts in your template, ask for posts sorted by your custom field in a meta_query:

$song_query = new WP_Query(
        'post_type' => 'songs',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',
        'meta_key' => 'index_position',
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.