NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

formats.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. function make_taxonomy_endpoint_for( $terms ) {
  3. $type_slugs = [];
  4. foreach ($terms as $type_slug):
  5. array_push($type_slugs, $type_slug->slug);
  6. endforeach;
  7. return $type_slugs;
  8. }
  9. function default_post_format( $item, $include_content ) {
  10. $filtered = [];
  11. $filtered[id] = $item->ID;
  12. $filtered[slug] = $item->post_name;
  13. $filtered[type] = $item->post_type;
  14. $filtered[title] = $item->post_title;
  15. $filtered[excerpt] = $item->post_excerpt;
  16. $filtered[date] = $item->post_date;
  17. if(!$filtered[excerpt]) {
  18. $filtered[excerpt] = get_the_excerpt($item);
  19. }
  20. if($include_content) $filtered[content] = $item->post_content;
  21. $filtered[featured] = get_the_post_thumbnail_url($item);
  22. if(!$filtered[featured]) {
  23. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  24. $filtered[featured] = get_post($thumbnailId)->guid;
  25. }
  26. // Materials + type endpoints
  27. // if($item->post_type === 'artist' || $item->post_type === 'event' || $item->post_type === 'exhibition') {
  28. $posts_with_type = ['artist', 'exhbition', 'event'];
  29. if( in_array($item->post_type, $posts_with_type) ) {
  30. $filtered[materials] = make_taxonomy_endpoint_for( get_the_terms( $item, 'material' ) );
  31. $filtered[subtypes] = make_taxonomy_endpoint_for( get_the_terms( $item, $item->post_type . '_type' ) );
  32. }
  33. // Custom fields endpoint
  34. if($item->post_type === 'episode') $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
  35. if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
  36. if($item->post_type === 'event') {
  37. $filtered[start] = get_post_meta( $item->ID, 'event-start-time', true );
  38. $filtered[end] = get_post_meta( $item->ID, 'event-end-time', true );
  39. }
  40. if($item->post_type === 'exhibition') {
  41. $filtered[start] = get_post_meta( $item->ID, 'exhibit-start-date', true );
  42. $filtered[end] = get_post_meta( $item->ID, 'exhibit-end-date', true );
  43. }
  44. // Post categories and tags (store just the slugs)
  45. if($item->post_type === 'post') {
  46. $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
  47. $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
  48. }
  49. return $filtered;
  50. }
  51. ?>