@klekovkinandrey

Что не так с выводом похожих записей по типу?

Смотрю в книгу вижу ***

есть типы записей, в одной категории похожие материалы выводит в другой вообще
хотя записи все прикреплены к категориям

function

if ( ! function_exists( 'get_renter_types' ) ) {
		function get_renter_types( $args = array( 'first_level' => FALSE ) ) {
			$renter_types  = get_terms( array(
				'taxonomy'   => 'renter_type',
				'term_taxonomy_id'   => isset( $args[ 'parentID' ] ) ? $args[ 'parentID' ] : 0,
				'hide_empty' => FALSE,
				'slug'       => ( isset( $args[ 'slug' ] ) ? $args[ 'slug' ] : '' ),
			) );
			$shops_term_id = get_term_by( 'slug', 'shops', 'renter_type' )->term_id;
			$result        = array();

			foreach ( $renter_types as $k => $v ) {
				if ( ( ( isset( $args[ 'first_level' ] ) && $args[ 'first_level' ] ) && $v->term_id != $shops_term_id ) || $v->parent != 0 ) {
					$term_id   = $v->term_id;
					$term_meta = get_option( "taxonomy_${term_id}" );

					$result[] = array(
						"icon"     => $v->description,
						"name"     => $v->name,
						"term_id"  => $v->term_id,
						"color"    => isset( $term_meta[ 'renter_type_color' ] ) ? esc_attr( $term_meta[ 'renter_type_color' ] ) : '#FF0000',
						"priority" => isset( $term_meta[ 'renter_type_priority' ] ) ? esc_attr( $term_meta[ 'renter_type_priority' ] ) : 10,
					);
				}
			}

			usort( $result, function ( $a, $b ) {
				return ( intval( $a[ 'priority' ] ) < intval( $b[ 'priority' ] ) ) ? 1 : - 1;
			} );

			return $result;
		}
	}


Вывод в шаблоне
$parent = get_the_terms($post->ID, 'renter_type');
					$parentID = is_array($parent) && $parent? $parent[0]->term_id : 0;			$sc_ids = array_map( function ( $item ) {
                    return $item[ 'term_id' ];
                    }, get_renter_types( array(/*'slug' => 'facilities-and-services', 'first_level' => TRUE,*/ 'parentID' => $parentID ) ) );
                    $shops = get_posts( array(
                        'post_type'      => 'renter',
			'cat'=>	$info,
                        'posts_per_page' => - 4,
                        'orderby'        => 'title',
                        'order'          => 'ASC',
                        'tax_query'      => array(
                            array(
                                'taxonomy' => 'renter_type',
                                'field'    => 'id',
                                'terms'    => $sc_ids,
                            ),
                        ),
                    ) );
                    $shops_en = array();
                    $shops_ru = array();
                    foreach ( $shops as $k => $v ) {
                        $meta = get_post_meta($v->ID);
                        $hop = array(
                            'id'        => $v->ID,
                            'name'      => $v->post_title,
                            'post_name' => $v->post_name,
                            'icon' 		=> is_array($meta['renter_logo']) && $meta['renter_logo']? wp_get_attachment_image_url( $meta['renter_logo'][0], 'thumbnail' ) : '',//get_term($sc_ids)->description, renter_gallery, service
							
                            'keywords'  => ( isset( $meta[ "renter_keywords" ] ) && ! empty( $meta[ "renter_keywords" ] ) ? $meta[ "renter_keywords" ][ 0 ] : "" ),
                        );
                        if ( is_lat( $v->post_title ) ) {
                            $shops_en[] = $hop;
                        } else {
                            $shops_ru[] = $hop;
                        }
                    }
                    $shops_ = array(
                        "en" => $shops_en,
                        "ru" => $shops_ru,
                    );
                    echo "<script>window.shops = " . json_encode( $shops_ ) . ";</script>";
  • Вопрос задан
  • 13 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы