Advanced Views Docs
Live PlaygroundDownload PluginGet PRO
  • 💡Help Centre
  • ⚡Getting Started
    • Introduction
      • Key Aspects
      • Creating Your First View
      • Creating Your First Card
      • Plugin Terms
      • Plugin Interface
        • Field Options
    • Installation
      • Advanced Views Lite
      • Advanced Views Pro
      • Comparison Table
      • Upgrading from Lite to Pro
    • Supported data vendors
    • Starter theme
  • 🌟Display Content
    • WordPress
      • Post
      • Taxonomy terms
      • User
      • Comments
      • Menus
    • WooCommerce Product
    • Meta fields
      • Basic fields
        • Number
      • Content fields
        • Image
        • File
        • WYSIWYG
        • oEmbed
        • Gallery
      • Choice fields
        • Select/checkbox/radio
        • True / False
      • Relationship fields
        • Link
        • Post_object
        • Page Link
        • Relationship
        • Taxonomy
        • User
      • Advanced fields
        • Google Map
        • Google Map Multiple Markers
        • ACF OpenStreetMap Field
        • Date/time picker
      • Layout fields
        • Group (Pro)
        • Repeater (Pro)
        • Flexible (Pro)
    • Object fields
    • Custom Data (Pro)
    • Custom Gutenberg Blocks (Pro)
    • Mount Points (Pro)
    • Front-end assets management (Pro)
  • 🦸‍♂️Query Content
    • Basic Filters
    • Meta Filters (Pro)
      • Current Post
      • Comparison
      • Dynamic Injection
    • Taxonomy Filters (Pro)
    • Pagination (Pro)
    • Custom Data (Pro)
  • 🏆Shortcode Attributes
    • Common Arguments
    • View Shortcode
    • Card Shortcode
  • 🧙‍♂️Templates
    • Customizing the Template
    • Template engines
      • Twig
      • Blade
    • CSS & JS
      • BEM Methodology
      • WordPress Interactivity API
    • File system storage
    • Pre-built components
    • Reusable components library (Pro)
    • Live reload
    • Multilingual
    • Custom Ajax & Rest API (Pro)
  • ☕Guides
    • Display Custom Post Type (CPT) on another post
    • Display Employees (CPT) of a Company (CPT)
    • Display Nested Repeater Fields
    • Map Marker from ACF Image
    • Display all CPT items on a single map
  • 🛠️Tools
    • Export/Import
    • Demo Import
    • Settings
    • Preview
  • 🏹Troubleshooting
    • Compatibility
    • Report a bug
    • Payment Issues
    • Lite Support (Forum)
    • Pro Support
  • ⚙️Customization
    • Filters and Hooks
      • View
      • Card
    • Suggest a feature
    • Performance
Powered by GitBook
On this page

Was this helpful?

  1. Guides

Display Employees (CPT) of a Company (CPT)

In this document we make use of Meta Filters which is a Pro feature.

PreviousDisplay Custom Post Type (CPT) on another postNextDisplay Nested Repeater Fields

Last updated 11 months ago

Was this helpful?

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 Card for Company CPT, which will display all Employees of the current Company.

Step by step guide

Create a View, then add the fields of your Employees CPT.

Next, Create or edit a Card, 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.

Choose Equal to in the Comparison setting.

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

  1. Use the special $post$ value if you’re going to paste a Card 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 Card, and paste the Card shortcode in the target place.

That’s it, you’re done.

Behind the scenes, it does the necessary trick of wrapping 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.

Find out more about .

☕
querying relationship fields in the official ACF article