For 99% of cases, no, you can’t.
Serialised data is not something you can search, and that is the fundamental problem. Not how to search it, but that it was serialised to begin with. Serialising is unnecessary. This is for the same reasons you cannot unscramble an egg, serialised data, especially PHP serialised data, is not built to be searched, neither is the database optimised for it.
So, the solution is to store the data you which to search for as independent post meta that can be searched. Or better yet, avoid ultra expensive post meta queries entirely and store the data you want to search by in taxonomy terms ( as was originally designed for and intended ).
For that 1% of situations, you might be able to use a LIKE
type search looking for the value if it’s already known, but you run the risk of false positives, and, this will be a super slow/expensive/heavy query. If it works.
In future, there are some important pieces of information that will assist you:
- Meta keys are not unique, you can add multiple values with the same meta key via
add_post_meta
, then retrieve them as an array withget_post_meta
by setting the 3rd parameter tofalse
. You don’t need serialisation for repeatable fields. - You don’t need serialised strings to store structured arrays. Using 3 meta key/value pairs called
company_name
company_id
andcompany_address
is far better than a singlecompany
meta with a serialised structure that hasid
name
andaddress
internal fields
I know it’s very bad practice to use serialized data for meta values, but I don’t know how to get around it – it’s how Pods works. It’s looking like I’m going to have to bin Pods and try and do this another way, but I really don’t want that to be the case…
- You don’t have to use Pods for everything, you can use Pods and then use an extra plugin library or manually written code
- Pods support and documentation might have answers for this, but 3rd party plugin support is off-topic on this site.
- Even if Pods cannot be changed, that doesn’t prevent you saving additional duplicated data via filters and hooks that can be queried against.
- Use a taxonomy for things you want to filter/query/search for. Post meta is optimised for finding key/values when you already know the post ID. Turning that upside down means the cost of the query gets big very quickly, and does not scale. It’s one of the biggest causes of slowness on WordPress sites.