Home › Forums › Front-end Issues › Wp_query with relationship to another custom post type › Reply To: Wp_query with relationship to another custom post type
Below are the arguments for a WP_Query I created recently that hopefully you can pick apart and make sense of for your use case:
$projects_args = array( 'post_type' => 'projects', 'post_status' => 'publish', 'relation' => 'AND', 'meta_query' => array( array( 'key' => 'cc_project_complete', 'value' => FALSE, 'compare' => '=' ), array( 'key' => 'cc_project_customer', 'value' => $customer_id, 'compare' => '=' ) ), 'fields' => 'id, title, cc_project_job_num, cc_project_load_ship_date, cc_project_asap, cc_project_po_received_date, cc_project_dept_planned_1, cc_project_dept_planned_2, cc_project_dept_planned_3, cc_project_dept_planned_4, cc_project_dept_planned_5, cc_project_dept_planned_6, cc_project_dept_planned_7, cc_project_dept_planned_8, cc_project_dept_planned_9, cc_project_dept_planned_10, cc_project_dept_planned_11, cc_project_dept_planned_12, cc_project_dept_planned_13, cc_project_dept_planned_14, cc_project_dept_planned_15, cc_project_urgency, cc_project_asap_lead_time, cc_project_rush_lead_time, cc_project_standard_lead_time, cc_project_complete, cc_project_customer' );
‘cc_project_complete’ is my True/False ACF field. Also… you can decide what fields to return using ‘fields’. And in this example… I made sure that 2 criteria were satisfied by using ‘relation’ => ‘AND’ with my ‘meta_query’
Hope that steers you in the right direction.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!