• hi.
    i am trying to find a way to sort my query posts by “meta_id”.

    custom fields are ordered randomly, and I can’t find a way to sort them based on their “meta_id” numerical value.

    has anyone done that before?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Are you talking about sorting all your posts by the meta_id?

    Or are you talking about when display each post, that the related custom fields for that post are sorted in meta_id order?

    I am looking to do the same thing.

    I have multiple values assigned to respective custom fields and need to be able to have them spit out in the order they were entered. Right now, I’m not sure what’s happening, but when pulling the arrays using get_post_custom(), is that the keys are not coming out in the right order.

    As an example, I’m entering items into custom fields in the following order:

    [keyX] => Item 1
    [keyX] => Item 2
    [keyX] => Item 3
    [keyX] => Item 4
    [keyY] => Item 1
    [keyY] => Item 2
    [keyY] => Item 3
    [keyY] => Item 4

    …and when I do my foreach loops so I can place them into the templates, they come out like so:

    [keyX] => Item 4
    [keyX] => Item 2
    [keyX] => Item 1
    [keyX] => Item 3
    [keyY] => Item 3
    [keyY] => Item 1
    [keyY] => Item 2
    [keyY] => Item 4

    Now, the astute will notice that those patterns are the same, but inverse; and both the incorrect order.

    Now I’ve looked at the post_meta table in the db, and the meta_id values for each entry are all in the right order for each key were I to have them sorted ascending by meta_id.

    So if I know at what stage, and based on what criteria, get_post_custom() sorts by default, or I can figure out how to sort the results of a better query by meta_id, then I should be able to ensure the results get spit out in the proper order in my template.

    Any help would be GREATLY APPRECIATED!!!!

    Thanks in advance.

    Im looking for this too, would be really good if someone could respond..

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘order by ‘meta_id’’ is closed to new replies.