• There is custom field “color” in posts with set of hex color codes (all in one custom field, separated with one space). Examples of custom field values for 5 posts:

    "000000 f0f0f0 c0c0c0 202020 404040 "
    "0000ee 555333 cc0000 602040 003399 "
    "9999cc 0000cc 0099ff 204010 552299 "
    "406040 ffffff ffcccc 000000 202020 "
    "cc0000 99ffcc cc9900 ff9999 000000 "

    Posts 1, 4 and 5 have same color “000000” posts 1 and 4 have same color “202020”, and posts 2 and 5 have same color “cc0000”.

    In my example most used single colors would be: “000000”, “202020” and “cc0000”.

    How to show most used single colors (not whole set of colors), for example 20 most used single colors? Any way to find out which colors are most used?

    Also, is there any method to get list of all unique single color codes?

Viewing 2 replies - 1 through 2 (of 2 total)
  • As they’re stored all in the same field, it’s not an easy thing to do. If it was a single value stored in the field and not a set of values, you could easily write a small SQL query that would select the values, and order by the most common. As you’ve got them stored like that, it’s a lot more involved…

    You’ll need to read in every entry for that meta key, get the row, split the result in spaces to get an array of values for that row, then check each one of those values to see if it already exists. if it doesn’t, add it to your list, and if it does, increment it’s count. After all of that, then you can sort the values list from highest to lowest counts.

    So yeah… it’s not an easy process, and will take a bit of processing power to get through depending on just how many records you’re storing there. But it can be done.

    Thread Starter Advanced SEO

    (@jole5)

    Hello.

    Thank you for your answer. I thought it is not an easy process and I am not “very awesome” with PHP. After reading your explanation I can imagine how complicated is that.

    Also, I thought it could be resources consuming, there is 25000 posts with that custom field. I thought, I could on custom page template generate list of popular colors once, and then cache it, or manually create display for further use. After all, list of 100 most used colors, based on 25000 posts, is not going to change a lot with new posts.

    So, if you have time, good will and if this is good enough challenge for you I would appreciate if you can make that for me.

    If you have any suggestion, or proposition how this can be done, please do not hesitate to tell.

    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Most used uunique custom field values?’ is closed to new replies.