Home Forums General Issues Change Post Archive Image with Filters Reply To: Change Post Archive Image with Filters

  • Hi @realph

    Thanks for the question, it is very clear to see what you are attempting to do.

    The above will not be easy, but it is not impossible. Lets start with filtering the products that are ‘blue’.

    You can use this tutorial here to query sub field values:

    This tutorial may seem a bit complex, but your task here is to find all the $rows in the postmeta table, where ‘blue’ was selected.

    Withing the $rows loop, you can find the post_id like so $post_id = $row->post_id;

    This allows to get the product ID that contains this ‘blue’ color. Instead of assigning this to a variable called $post_id, you should append it to an array like so: $ids[] = $row->post_id;

    After your loop is complete, you should have a populated $ids array which you can now use in a WP_Query argument in the ‘posts__in’ arg!

    To show the blue image as the featured one, just loop through all the repeater rows and then match the ‘product_colour’ value to the current queried color. When a match is found, display that image!