When importing you could create a taxonomy for each unique stance key, then add the value as a term to the taxonomy for that key, then assign that term to the post.
I’d suggest something like:
- Store the stance keys somewhere in the database (probably as options), making sure that you don’t have duplicates. Depending on how many you have, this could probably just be a single value with a serialised array.
- On the
init
hook, read the list of keys withget_option()
, and register a taxonomy for each one withregister_taxonomy()
. - When importing, save any new keys to the database, and immediately run
register_taxonomy()
for them so that the taxonomy is registered for the rest of the process. - For the values, add them as terms to the taxonomy using
wp_insert_term()
, but only after checking that value doesn’t already exist withget_term_by()
. - Once the taxonomy has been registered, and the term for the value has been inserted or found, assign the term to the post using
wp_set_post_terms()
.
If you do that then you can easily filter posts based on these values with a taxonomy query. This will be faster than attempting to filter using post meta.