| @@ -87,23 +87,19 @@ | ||
| 87 | 87 | if( JSON::isJson( $args['taxonomies'] ) ){ |
| 88 | 88 | $taxonomies = JSON::decode( $args['taxonomies'] ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if( !empty( $taxonomies->category ) ){ | |
| 92 | - $queryArgs['tax_query'][] = [ | |
| 93 | - 'taxonomy' => 'category', | |
| 94 | - 'field' => 'slug', | |
| 95 | - 'terms' => $taxonomies->category | |
| 96 | - ]; | |
| 91 | + if ( !empty( $taxonomies ) ) { | |
| 92 | + foreach( $taxonomies as $taxonomySlug => $value ) { | |
| 93 | + if ( !empty( $value ) ) { | |
| 94 | + $queryArgs['tax_query'][] = [ | |
| 95 | + 'taxonomy' => $taxonomySlug, | |
| 96 | + 'field' => 'slug', | |
| 97 | + 'terms' => $value | |
| 98 | + ]; | |
| 99 | + } | |
| 100 | + } | |
| 97 | 101 | } |
| 98 | - | |
| 99 | - if( !empty( $taxonomies->post_tag ) ){ | |
| 100 | - $queryArgs['tax_query'][] = [ | |
| 101 | - 'taxonomy' => 'post_tag', | |
| 102 | - 'field' => 'slug', | |
| 103 | - 'terms' => $taxonomies->post_tag | |
| 104 | - ]; | |
| 105 | - } | |
| 106 | 102 | } |
| 107 | 103 | |
| 108 | 104 | if( Data::isTrue( $args['excludeNonThumbnail'] ) ){ |
| 109 | 105 | $queryArgs['meta_query'][] = [ |
| @@ -121,16 +117,20 @@ | ||
| 121 | 117 | |
| 122 | 118 | $records = []; |
| 123 | 119 | |
| 124 | 120 | if ( $availableRecords && $availableRecords->have_posts() ) { |
| 121 | + $acfModule = \Depicter::resolve( 'depicter.dataSources.tags.acf' ); | |
| 122 | + $acfModuleAvailable = $acfModule->isAvailable(); | |
| 123 | + $acfFields = $acfModule->getFieldGroups( $args ); | |
| 124 | + | |
| 125 | 125 | foreach( $availableRecords->posts as $post ) { |
| 126 | - $featuredImage = []; | |
| 126 | + $featuredImage = null; | |
| 127 | 127 | if( has_post_thumbnail( $post->ID ) ){ |
| 128 | 128 | $featuredImageId = get_post_thumbnail_id( $post->ID ); |
| 129 | 129 | $imageInfo = wp_get_attachment_image_src( $featuredImageId, 'full' ); |
| 130 | 130 | $featuredImage = [ |
| 131 | 131 | 'id' => $featuredImageId, |
| 132 | - 'url' => $imageInfo[0] ?: '', | |
| 132 | + 'src' => $imageInfo[0] ?: '', | |
| 133 | 133 | 'width' => $imageInfo[1] ?: '', |
| 134 | 134 | 'height' => $imageInfo[2] ?: '', |
| 135 | 135 | ]; |
| 136 | 136 | } |
| @@ -140,9 +140,9 @@ | ||
| 140 | 140 | 'id' => $post->ID, |
| 141 | 141 | 'title' => get_the_title( $post->ID ), |
| 142 | 142 | 'url' => get_permalink( $post->ID ), |
| 143 | 143 | 'featuredImage' => $featuredImage, |
| 144 | - 'date' => get_the_date('', $post->ID ), | |
| 144 | + 'date' => get_the_date('Y-m-d h:m:s', $post->ID ), | |
| 145 | 145 | 'excerpt' => $excerpt, |
| 146 | 146 | 'author' => [ |
| 147 | 147 | 'name' => get_the_author_meta( 'display_name', $post->post_author ), |
| 148 | 148 | 'page' => get_author_posts_url( $post->post_author ), |
| @@ -147,11 +147,12 @@ | ||
| 147 | 147 | 'name' => get_the_author_meta( 'display_name', $post->post_author ), |
| 148 | 148 | 'page' => get_author_posts_url( $post->post_author ), |
| 149 | 149 | ], |
| 150 | 150 | 'content' => get_the_content(null, false, $post->ID ), |
| 151 | - 'taxonomies'=> [] | |
| 151 | + 'taxonomy'=> [] | |
| 152 | 152 | ]; |
| 153 | 153 | |
| 154 | + // append taxonomy data | |
| 154 | 155 | $taxonomies = get_object_taxonomies( $args['postType'], 'objects' ); |
| 155 | 156 | |
| 156 | 157 | if ( !empty( $taxonomies ) ) { |
| 157 | 158 | foreach( $taxonomies as $taxonomySlug => $taxonomy ) { |
| @@ -167,8 +168,32 @@ | ||
| 167 | 168 | 'id' => $term->term_id, |
| 168 | 169 | 'value' => $term->slug, |
| 169 | 170 | 'label' => $term->name, |
| 170 | 171 | 'link' => get_term_link( $term->term_id ) |
| 172 | + ]; | |
| 173 | + } | |
| 174 | + } else { | |
| 175 | + $taxonomyInfo[ "terms" ] = null; | |
| 176 | + } | |
| 177 | + | |
| 178 | + $postInfo['taxonomy'][ $taxonomySlug ] = $taxonomyInfo; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + | |
| 182 | + // append acf data | |
| 183 | + if( $acfModuleAvailable ){ | |
| 184 | + $postInfo['acf'] = []; | |
| 185 | + | |
| 186 | + if ( !empty( $acfFields ) ) { | |
| 187 | + foreach( $acfFields as $fieldId => $field ) { | |
| 188 | + $postInfo['acf'][ $fieldId ] = $acfModule->getSlugValue( $fieldId, ['post' => $post->ID ] ); | |
| 189 | + if( $field['type'] === 'image' ){ | |
| 190 | + $imageInfo = wp_get_attachment_image_src( $postInfo['acf'][ $fieldId ], 'full' ); | |
| 191 | + $postInfo['acf'][ $fieldId ] = [ | |
| 192 | + 'id' => $postInfo['acf'][ $fieldId ], | |
| 193 | + 'src' => $imageInfo[0] ?? '', | |
| 194 | + 'width' => $imageInfo[1] ?? '', | |
| 195 | + 'height' => $imageInfo[2] ?? '', | |
| 171 | 196 | ]; |
| 172 | 197 | } |
| 173 | 198 | } |
| 174 | 199 | } |