Support » Plugins » Hacks » List all custom field values in archive page

  • Resolved s

    (@stepunk)


    Hello,
    I have a custom post type PRODUCT with a custom field called COLOR.

    How can i list all the COLOR values in the archive page?

    Basically I want to be able to have a list of all colors associated to products in the current archive, so I can filter them also based on a specific color, but only if the COLOR is associated at least to a PRODUCT in the specified archive (PRODUCT archive, but also in a CATEGORY archive, TAG archive, etc…)

    Thanks a lot!
    Stefano

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You can get all unique color values in the postmeta table with a SQL query like SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key = 'color';

    If other post types have a color field, or you only want colors from a certain date range, etc., you need to join the posts table to apply more criteria, but the idea is the same.

    Alternately, you could get the color value for each post in the archive loop and push it into an array. Then use array_unique() to get rid of duplicates.

    Thread Starter s

    (@stepunk)

    I ended up implementing the COLOR as a custom taxonomy. Now everything is easier 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List all custom field values in archive page’ is closed to new replies.