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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. }
  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($include_content) {
  18. $content = $item->post_content;
  19. $content = apply_filters('the_content', $content);
  20. $filtered[content] = wp_specialchars_decode($content);
  21. }
  22. if(!$filtered[excerpt]) {
  23. $excerpt = get_the_excerpt($item);
  24. $filtered[excerpt] = wp_specialchars_decode($excerpt);
  25. }
  26. $filtered[featured] = get_the_post_thumbnail_url($item);
  27. if(!$filtered[featured]) {
  28. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  29. $filtered[featured] = get_post($thumbnailId)->guid;
  30. }
  31. $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
  32. if(!$filtered[thumb]) {
  33. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  34. $filtered[thumb] = get_post($thumbnailId)->guid;
  35. }
  36. $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
  37. // Materials + type endpoints
  38. $posts_with_type = ['artist', 'exhbition', 'event'];
  39. if( in_array($item->post_type, $posts_with_type) ) {
  40. $filtered[materials] = make_taxonomy_endpoint_for(get_the_terms( $item, 'material'));
  41. $filtered[subtypes] = make_taxonomy_endpoint_for(get_the_terms( $item, $item->post_type . '_type' ));
  42. }
  43. // Custom fields endpoint
  44. if($item->post_type === 'episode' && $include_content) $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
  45. if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
  46. $posts_with_date = ['exhbition', 'event'];
  47. if( in_array($item->post_type, $posts_with_date) ) {
  48. $filtered[start] = get_post_meta($item->ID, $item->post_type . '-start-time', true);
  49. $filtered[end] = get_post_meta($item->ID, $item->post_type . '-end-time', true);
  50. $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
  51. }
  52. // Post categories and tags (store just the slugs)
  53. if($item->post_type === 'post') {
  54. $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
  55. // $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
  56. }
  57. if($item->related_episode) {
  58. $filtered[related_episode] = strtolower($item->related_episode);
  59. }
  60. return $filtered;
  61. }
  62. function minimal_post_format( $item, $include_excerpt ) {
  63. $filtered = [];
  64. $filtered[id] = $item->ID;
  65. $filtered[slug] = $item->post_name;
  66. $filtered[type] = $item->post_type;
  67. $filtered[title] = $item->post_title;
  68. $filtered[date] = $item->post_date;
  69. $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
  70. if(!$filtered[thumb]) {
  71. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  72. $filtered[thumb] = get_post($thumbnailId)->guid;
  73. }
  74. // Always include a small excerpt for artists
  75. // because they appear on the episode page
  76. $posts_with_excerpt = ['artist'];
  77. if( in_array($item->post_type, $posts_with_excerpt) ) {
  78. $filtered[excerpt] = $item->post_excerpt;
  79. if(!$filtered[excerpt]) {
  80. $excerpt = get_the_excerpt($item);
  81. $filtered[excerpt] = wp_specialchars_decode($excerpt);
  82. }
  83. }
  84. // Always include a date for date based types
  85. $posts_with_date = ['exhbition', 'event'];
  86. if( in_array($item->post_type, $posts_with_date) ) {
  87. $filtered[start] = get_post_meta($item->ID, $item->post_type . '-start-time', true);
  88. $filtered[end] = get_post_meta($item->ID, $item->post_type . '-end-time', true);
  89. $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
  90. }
  91. return $filtered;
  92. }
  93. ?>