Order metadata when retrieving via get_metadata()
-
Hi –
I’m probably pushing this functionality beyond what it was intended, but my customer wants to upload CSV product tables and then have that data listed in posts. There are hundreds of these spreadsheets. I’ve got this all working using post metadata, but when I generate the metadata for a post using get_metadata() it comes back in “random order” (not clear what controls it). I was assuming/hoping it would list the metadata in the order that it was inputted – ie, the meta key value, which is also the order of my spreadsheet. Unfortunately it doesn’t. I guess I could get around this by doing a direct database query, but was hoping to just use the WP functions as that is how I have it all set up now.
Another idea is to order the csv columns by placing numbers in front of them and then ordering the metadata array by that and stripping them for output. But that is kind of time consuming given the number of spreadsheets involved and not very elegant either.
Note that the spreadsheets have different column names, so I can’t call up the metadata by name, which would also solve the problem. It has to generate the entire list and spit out the value – key pair.
Well, if I don’t hear any ideas I’ll just go with the direct database query and order the results by metadata key.
Any thoughts on this?
- The topic ‘Order metadata when retrieving via get_metadata()’ is closed to new replies.