Background Information:
get_field () has three parameters:
$field_name : the name of the field to retrieve. e.g. "page_content" (required)$post_id : The specific identifier of the message in which your value was entered. By default, the current message identifier is used (not required). It can also be parameters / taxonomies / users / etc$format_value
If you were only interested in grabbing a specific record (from which you knew the identifier), the key would be the second parameter ( $post_id ). There is nothing magical about ACF. Quite simply: meta_value (i.e. the directory in which the message is placed is attached) is stored in each message ( $post_id attached to this message).
However, in your case, we do not know the identifier of the messages we want to receive.
Decision:
If we explain what you want to do in a simple sentence, this sentence will look something like this:
Show / receive messages on a directory_listings page (a custom message type) that has a meta_value that points to this page.
Obviously, you cannot use get_field() because your problem has nothing to do with getting the field. Rather, you need to "find messages that have a specific field." ACF has excellent documentation on this .
Luckily for you, WordPress comes with an awesome class called WP_Query , and a similarly awesome function is called get_posts () . Therefore, looking back at our suggestion above and translating it into a function, we want: get_posts() , where meta_key has the value current $post_id .
Or, more specifically, on the directory_listings page, you will receive the following request:
$related_articles = get_posts(array( 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'related_articles', // name of custom field 'value' => '"' . get_the_ID() . '"', 'compare' => 'LIKE' ) ) )); if( $related_articles ): foreach( $related_articles as $article ): // Do something to display the articles. Each article is a WP_Post object. // Example: echo $article->post_title; // The post title echo $article->post_excerpt; // The excerpt echo get_the_post_thumbnail( $article->ID ); // The thumbnail endforeach; endif;