| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- function make_taxonomy_endpoint_for( $terms ) {
- $type_slugs = [];
- foreach ($terms as $type_slug):
- array_push($type_slugs, $type_slug->slug);
- endforeach;
- return $type_slugs;
- }
-
-
- function default_post_format( $item, $include_content ) {
- $filtered = [];
- $filtered[id] = $item->ID;
- $filtered[slug] = $item->post_name;
- $filtered[type] = $item->post_type;
- $filtered[title] = $item->post_title;
- $filtered[excerpt] = $item->post_excerpt;
- $filtered[date] = $item->post_date;
- if(!$filtered[excerpt]) {
- $filtered[excerpt] = get_the_excerpt($item);
- }
- if($include_content) $filtered[content] = $item->post_content;
-
- $filtered[featured] = get_the_post_thumbnail_url($item);
- if(!$filtered[featured]) {
- $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
- $filtered[featured] = get_post($thumbnailId)->guid;
- }
-
- // Materials + type endpoints
- // if($item->post_type === 'artist' || $item->post_type === 'event' || $item->post_type === 'exhibition') {
- $posts_with_type = ['artist', 'exhbition', 'event'];
- if( in_array($item->post_type, $posts_with_type) ) {
- $filtered[materials] = make_taxonomy_endpoint_for( get_the_terms( $item, 'material' ) );
- $filtered[subtypes] = make_taxonomy_endpoint_for( get_the_terms( $item, $item->post_type . '_type' ) );
- }
-
- // Custom fields endpoint
- if($item->post_type === 'episode') $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
-
- if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
-
- if($item->post_type === 'event') {
- $filtered[start] = get_post_meta( $item->ID, 'event-start-time', true );
- $filtered[end] = get_post_meta( $item->ID, 'event-end-time', true );
- }
- if($item->post_type === 'exhibition') {
- $filtered[start] = get_post_meta( $item->ID, 'exhibit-start-date', true );
- $filtered[end] = get_post_meta( $item->ID, 'exhibit-end-date', true );
- }
-
- // Post categories and tags (store just the slugs)
- if($item->post_type === 'post') {
- $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
- $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
- }
-
- return $filtered;
- }
-
- ?>
|