Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. add_filter('acf/load_field/name=room', 'populateRooms');
  2. function populateRooms($field)
  3. {
  4. $field['choices'] = array();
  5. wp_reset_query();
  6. $query = new WP_Query(array(
  7. 'post_type' => 'room',
  8. 'orderby' => 'menu_order',
  9. 'order' => 'ASC',
  10. 'posts_per_page' => -1,
  11. 'tax_query' => array(
  12. array(
  13. 'taxonomy' => 'room_category',
  14. 'field'=>'slug',
  15. 'terms' => 'vacant',
  16. )
  17. )
  18. ));
  19. $field['choices'] = array();
  20. foreach ($query->posts as $room_id => $matched_room) {
  21. $choices[$matched_room->ID] = $matched_room->post_title;
  22. }
  23. if (is_array($choices)) {
  24. foreach ($choices as $key => $choice) {
  25. $field['choices'][$key] = $choice;
  26. }
  27. }
  28. wp_reset_query();
  29. return $field;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement