# Display Employees (CPT) of a Company (CPT)

#### Scenario example:

Let’s imagine that you have a Company and Employee CPT. Every Employee has a post\_object field, where the current Company of the Employee is selected.

Our goal is to create a *Post Selection* for Company CPT, which will display all Employees of the current Company.

### Step by step guide

**Create** a *Layout*, then **assign** the fields of your Employees CPT.

Next, **Create** or edit a *Post Selection*, which will **query posts** by the relationship/post\_object field.

**Switch** to the *Meta Filters* tab.

**Click** on the **Add Rule** button and then **Add Field** button to create a new Meta Rule, then select the target relationship/post\_object field.&#x20;

**Choose** *Equal to* in the **Comparison** setting.

<figure><img src="https://2293383029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FN2nAC4pTDjEmDu8ZkLB2%2Fuploads%2FzdchefCMbxlRfWtk3vpm%2Fcompare-current-id.jpg?alt=media&#x26;token=ebb25de4-c199-4eb7-89fa-714c9028c31d" alt=""><figcaption></figcaption></figure>

**Define** a value, which can be done in a couple of ways.

1. Use the special `$post$` value if you’re going to paste the shortcode on a Page or Post, of which the ID should be used in the meta\_query.  This means the `$post$` will be replaced with an ID of the Post, where you’ve pasted the shortcode, and the query will find all Posts, where the relationship/post\_object field of the current post ID is chosen.\
   In our Company example this fits perfectly well and can be used to display all Employees on the Company CPT.
2. Numeric ID of the target Post. \
   If you want to query all posts which have the specific Post selected in their relationship/post\_object field, but this specific Post is different from the Page where you’re going to paste the shortcode, then you must define a numeric ID of that specific Post.\
   In our Company example this can be used to display all Employees for the specific Company CPT on the homepage or another page.
3. Use the relation field alias i.e. `$post$.your-field` to find all posts that have the same option selected as the current page. \
   **Note:** if the current page field contains multiple values, then it will get pages, where at least one matches.

**Save** the *Post Selection*, and paste the shortcode in the target place.

That’s it, you’re done.

Behind the scenes, it does the necessary trick of wrapping it into quotes and using 'Like' for comparison, so you won't need to take care of it. It'll work with all the field options for Single, Multiple select and all return formats of a field.&#x20;

Find out more about [querying relationship fields in the official ACF article](https://www.advancedcustomfields.com/resources/querying-relationship-fields/).
