There is an IM with this filter:

General view of the filter

"Collection" is an arbitrary field for the product. Suppose I am in the "Dresses" category. It is necessary that only those values ​​of an arbitrary field that the goods have in the current selection be displayed on the left (I mean those that are now selected on this category page and further by pagination).

So that there is no such thing that “fall” is displayed, although in this category no product of this sample has such a field value ...

  • No one has yet answered the question, because it is unclear how the filter was made and what code displays the "collection". - KAGG Design
  • It does not matter if a filter is made and how to display the collection. I know how to do this. The question is how to get the collection field values ​​for the current sample ... Next, sorting the array of data and filtering the sample is not a problem - Seredniy
  • well, since you all know, use get_post_meta () - KAGG Design
  • You do not read the question. The question is how to get data on which posts are currently in the sample. Going through one more cycle and guarding ID in the array does not look very optimized ... - Seredniy
  • So what about the current selection in no way to collect data about the fields? - br3t

1 answer 1

By registering get_post_meta (ID); get all the meta fields.

https://wp-kama.ru/function/get_post_meta

Using

$ meta_values ​​= get_post_meta ($ post_id, [$ key, [$ single]]); $ post_id (number) (mandatory) Post ID, arbitrary fields of which need to be obtained. Default: none $ key (string) The name of an arbitrary field whose value you want to get. If you leave the field empty, all arbitrary fields of the post will be received . Default: '' $ single (logical) true - returns the value of the meta field (if there are several fields, it will return the value of the first meta field). false - returns an array of all values ​​of meta fields with the specified key.

If a serialized array is in the value of an arbitrary field, then true will return a normal array, and if you specify false, then an array in the [0] element of which the same serialized array will be returned. Default: false

Accordingly, by running all the goods on this page and getting all the meta fields of each, by iterating through all the fields of each, we find what values ​​it has, add to the selection, if not yet added. Then, by sampling, we display only those that were encountered.

  • Alas, this is not what I asked. How to get the fields and how to process them for each post is clear. How to get data about which posts in the current sample without iterating through them in the main loop - Seredniy
  • Well, if we are talking about getting without iteration, get_metadata returns only inside a cycle; without iteration, there is an option to fulfill your query of the form $ ids = implode (',', $ products_ids); "SELECT * FROM wp_postmeta WHERE post_id IN ({$ ids}) AND meta_value <> 0" and customize the search criteria or iterate over the received values, as far as I understand, the entire list of functions for working with metafields wp-kama.ru/ function-cat / metadannye implies going through them in the loop of searching posts. - x-positive
  • Or look at the WP_Meta_Query wp-kama.ru/function/wp_meta_query addition to the WP_Query, you can get posts immediately, if you work on the principle of posts but for the fields - what you need, if not, then yourself)