I have to get posts having a particular meta value for a dynamic meta key
.
The meta key
values will be:
- _project_global_1_trend_link
- _project_global_2_trend_link
- etc…
The common text in meta key is trend_link
. So I need to add like operator
for meta key
.
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'projects',
'meta_query' => array(
array(
'key' => 'trend_link',
'value' => 10,
'compare' => 'LIKE'
)
)
));
By using this code I can apply like operator
on meta_value
.
But I need to apply
like operator
onmeta_key
.
Is there any way to apply like operator
on meta_key
.
Please help !!
2
Answers
If i’m correct you can add a dollar sign to the meta key for dynamic keys!
For this situation you can use a parameter "compare_key"