0

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?

  • OK, I solved in this way: 'meta_query' => array( array( 'key' => 'product', 'value' => '"'.get_the_id().'"', 'compare' => 'LIKE' ) ) – globdug Mar 28 at 14:18
  • Go ahead and add your comment as the answer, and then accept it. – NightHawk Mar 29 at 15:12
0

OK, I solved in this way:

'meta_query' => array(
  array(
    'key' => 'product',
    'value' => '"'.get_the_id().'"',
    'compare' => 'LIKE'
  )
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.