I'm using Advanced Custom Fields and Genesis and trying to modify a template to reflect a relationship between two custom post types (using their associated custom fields.) In this case, I have custom post types for "Staff" and "Reports", and for staff, I have the custom fields "first_name" and "last_name"; and associated with the "Reports" CPT, I also have two custom fields "primary_contact" and "associated_contact"— and in the "single-staff.php" template, I'd like to render a list of any associated reports in the sidebar that would include entries (post titles) for which that staff member is defined as either a "primary_contact" or an "associated_contact."
Thus, for example, if I've created "Tom Jones" as a staff member (an instance of the "Staff" post type), is it possible for me to define a query that outputs a list of reports for which "Tom Jones" is defined as a "primary_contact" and/or "associated_contact" in any instances of the "Reports" custom post type? I'm including a (very) rough concept for this query below:
$args = array( 'meta_query' => array( 'relation' => 'OR', array( 'post_type' => 'reports', 'meta_key' => 'primary_contact', 'meta_value' => '$this.full_name', ), array( 'post_type' => 'reports', 'meta_key' => 'associated_contact', 'meta_value' => '$this.full_name', ) ) ); $query = new WP_Query( $args );
Please let me know if the question is not sufficiently clear-- and thank you for any insight!