Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('acf/load_field/name=room', 'populateRooms');
- function populateRooms($field)
- {
- $field['choices'] = array();
- wp_reset_query();
- $query = new WP_Query(array(
- 'post_type' => 'room',
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'room_category',
- 'field'=>'slug',
- 'terms' => 'vacant',
- )
- )
- ));
- $field['choices'] = array();
- foreach ($query->posts as $room_id => $matched_room) {
- $choices[$matched_room->ID] = $matched_room->post_title;
- }
- if (is_array($choices)) {
- foreach ($choices as $key => $choice) {
- $field['choices'][$key] = $choice;
- }
- }
- wp_reset_query();
- return $field;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement