First of all, sorry this title, I really don't know how title the question without write a blobtext! :)
Anyway, my problem is this one: I have a custom post "Risorse" (en: Resources). It supports only titles, all other parameters are custom fields created with ACF. One of these is a relationship where I can select one or more pages. So, for example I can create a Resource and select a relationship with two pages. In DB it is saved in this way
a:2:{i:0;s:3:"727";i:1;s:3:"729";}
Now, when I load for example the page 727, I want to list all Resources that have a relation with that page.
I'm trying a custom query but I don't know how set the meta_query array. I tried something like:
'meta_query' => array(
array(
'key' => 'product',
'value' => get_the_id(),
'compare' => 'IN'
)
)
Obviously no posts are returned because the meta_key 'product' contains an array of values. How can I get all Resources the have a relation with a specific post?
First of all, sorry this title, I really don't know how title the question without write a blobtext! :)
Anyway, my problem is this one: I have a custom post "Risorse" (en: Resources). It supports only titles, all other parameters are custom fields created with ACF. One of these is a relationship where I can select one or more pages. So, for example I can create a Resource and select a relationship with two pages. In DB it is saved in this way
a:2:{i:0;s:3:"727";i:1;s:3:"729";}
Now, when I load for example the page 727, I want to list all Resources that have a relation with that page.
I'm trying a custom query but I don't know how set the meta_query array. I tried something like:
'meta_query' => array(
array(
'key' => 'product',
'value' => get_the_id(),
'compare' => 'IN'
)
)
Obviously no posts are returned because the meta_key 'product' contains an array of values. How can I get all Resources the have a relation with a specific post?
Share Improve this question edited Mar 28, 2019 at 22:32 NightHawk 1,48415 silver badges21 bronze badges asked Mar 28, 2019 at 13:28 globdugglobdug 32 silver badges5 bronze badges 2 |1 Answer
Reset to default 0OK, I solved in this way:
'meta_query' => array(
array(
'key' => 'product',
'value' => '"'.get_the_id().'"',
'compare' => 'LIKE'
)
)
'meta_query' => array( array( 'key' => 'product', 'value' => '"'.get_the_id().'"', 'compare' => 'LIKE' ) )
– globdug Commented Mar 28, 2019 at 14:18