NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

formats.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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($include_content) $filtered[content] = $item->post_content;
  18. $filtered[featured] = get_the_post_thumbnail_url($item);
  19. // Materials + type endpoints
  20. // if($item->post_type === 'artist' || $item->post_type === 'event' || $item->post_type === 'exhibition') {
  21. $posts_with_type = ['artist', 'exhbition', 'event'];
  22. if( in_array($item->post_type, $posts_with_type) ) {
  23. $filtered[materials] = make_taxonomy_endpoint_for( get_the_terms( $item, 'material' ) );
  24. $filtered[subtypes] = make_taxonomy_endpoint_for( get_the_terms( $item, $item->post_type . '_type' ) );
  25. }
  26. // Custom fields endpoint
  27. if($item->post_type === 'episode') $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
  28. if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
  29. if($item->post_type === 'event') {
  30. $filtered[start] = get_post_meta( $item->ID, 'event-start-time', true );
  31. $filtered[end] = get_post_meta( $item->ID, 'event-end-time', true );
  32. }
  33. if($item->post_type === 'exhibition') {
  34. $filtered[start] = get_post_meta( $item->ID, 'exhibit-start-date', true );
  35. $filtered[end] = get_post_meta( $item->ID, 'exhibit-end-date', true );
  36. }
  37. // Post categories and tags (store just the slugs)
  38. if($item->post_type === 'post') {
  39. $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
  40. $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
  41. }
  42. return $filtered;
  43. }
  44. ?>