admin管理员组文章数量:1429972
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'
)
)
本文标签: wp querywpqueryACF field and array
版权声明:本文标题:wp query - WP_Query, ACF field and array 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745555140a2663140.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'meta_query' => array( array( 'key' => 'product', 'value' => '"'.get_the_id().'"', 'compare' => 'LIKE' ) )
– globdug Commented Mar 28, 2019 at 14:18