skip to Main Content

I have a problem that I have publications that are assigned to articles and I need to display other publications that are assigned to given articles on the details of a given publication.

Each publication can be assigned to several articles and you need to download the 5 latest publications that are assigned to at least one of the same article.

The relationship is made by ACF, as a relationship from the publication to the article via the custom field "related_articles".

Unfortunately, this code does not return any publications. What am I doing wrong?

Thank you in advance for your help.

$related_articles = get_field('related_articles');

$args_related_publications = array(
  'post_type' => 'publications', 
  'posts_per_page' => 5,
  'orderby' => 'date',
  'order' => 'DESC',
  'post_status' => 'publish',
  'meta_query' => array(
    'relation' => 'OR',
    array(
      'key' => 'related_articles',
      'value' => $related_articles,
      'compare' => 'IN',    
    ),
  ),
);

$related_publications_query = new WP_Query($args_related_publications);

2

Answers


  1. Chosen as BEST ANSWER

    We managed to arrange with the client that he would select related publications himself, omitting the articles, so the topic is no longer relevant


  2. What field type of the "related_articles" ACF field you are using here?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search