It is quite difficult to concretely answer your question. The first part is easy though. I recently did something similar on stackoverflow
Meta keys are are compared and match exactly.
WP_Query have no means to adjust this behavior with a simple parameter, but we can always introduce one ourselves and then adjust the
posts_where clause to do a
LIKE comparison on meta keys.
This is just a basic filter, adjust it as needed.
add_filter( 'posts_where', function ( $where, \WP_Query $q )
// Check for our custom query var
if ( true !== $q->get( 'wildcard_on_key' ) )
// Lets filter the clause
$where = str_replace( 'meta_key =', 'meta_key LIKE', $where );
}, 10, 2 );
As you can see, the filter is only fired when we set our new custom parameter,
true. When this checks out, we simply change the
= comparator to the
Just a note on this,
LIKE comparisons are inherently more expensive to run that other comparisons
You can simply query your posts as follow to get all posts with meta keys
$args = [
'wildcard_on_key' => true,
'meta_query' => [
'key' => 'like_status_',
'value' => 1,
$query = new WP_Query( $args );
Custom fields does not have impact on performance, you can read my post on this subject here. I am however troubled by that you say each post can have hundreds or thousands of likes. This can hit you on performance getting and caching such a large amount of custom field data. It can also clog your db with a huge amount of unnecessary custom field data which makes it quite hard to maintain.
I am not a very big fan of storing serialized data in custom fields as one cannot search or order by serialized data. I would however suggest storing all the user ID's in an array under one custom field. You can simply just update the array with the user ID when a user like a post. Getting the custom field data and looping over the array of ID's and doing something with the ID's are easy. Just have a look at
Updating a custom field is also easy. For that, you will need to look into
update_post_meta(), I do not know how you create your custom fields, but
update_post_meta() is definitely something you would want to use.
If you need to send emails or push notifications when a custom field is updated, you have the following hooks available to work with. (See
update_metadata() for context)
Just before I post this, again, before you go the serialized route, make sure that you would not need to sort by the sorted data or search for particular data inside the serialized data.