Как пересортировать список постов добавив еще одну таксономию?

Пытаюсь пересортировать список постов, добавив в аргументы еще 1 таксономию, но не могу получить желаемый результат. Нужно добиться следующего:
1. Есть страница вывода таксономии по городу. Параметры сортировки получаю следующие:
spoiler
Array
(
    [property_city] => lvov
    [error] => 
    [m] => 
    [p] => 0
    [post_parent] => 
    [subpost] => 
    [subpost_id] => 
    [attachment] => 
    [attachment_id] => 0
    [name] => 
    [static] => 
    [pagename] => 
    [page_id] => 0
    [second] => 
    [minute] => 
    [hour] => 
    [day] => 0
    [monthnum] => 0
    [year] => 0
    [w] => 0
    [category_name] => 
    [tag] => 
    [cat] => 
    [tag_id] => 
    [author] => 
    [author_name] => 
    [feed] => 
    [tb] => 
    [paged] => 0
    [meta_key] => fave_featured
    [meta_value] => 
    [preview] => 
    [s] => 
    [sentence] => 
    [title] => 
    [fields] => 
    [menu_order] => 
    [embed] => 
    [category__in] => Array
        (
        )

    [category__not_in] => Array
        (
        )

    [category__and] => Array
        (
        )

    [post__in] => Array
        (
        )

    [post__not_in] => Array
        (
        )

    [post_name__in] => Array
        (
        )

    [tag__in] => Array
        (
        )

    [tag__not_in] => Array
        (
        )

    [tag__and] => Array
        (
        )

    [tag_slug__in] => Array
        (
        )

    [tag_slug__and] => Array
        (
        )

    [post_parent__in] => Array
        (
        )

    [post_parent__not_in] => Array
        (
        )

    [author__in] => Array
        (
        )

    [author__not_in] => Array
        (
        )

    [posts_per_page] => 15
    [ignore_sticky_posts] => 
    [suppress_filters] => 
    [cache_results] => 
    [update_post_term_cache] => 1
    [lazy_load_term_meta] => 1
    [update_post_meta_cache] => 1
    [post_type] => 
    [nopaging] => 
    [comments_per_page] => 50
    [no_found_rows] => 
    [taxonomy] => property_city
    [term] => lvov
    [order] => DESC
    [post_status] => publish
    [orderby] => meta_value date
)


2. Есть дополнительная таксономия "property_status", в которой есть числовое поле "sort_field". На выходе пытаюсь получить Сортировку всех постов с учётом поля "sort_field" в "property_status". То есть цель, добавить в выборку выше сортировку именно по этому полю, а не по "[orderby] => meta_value date" самих постов.

Исходный код вывода:
spoiler
<?php
/**
 * Common Taxonomy - Used by property taxonomies
 * Created by PhpStorm.
 * User: waqasriaz
 * Date: 08/01/16
 * Time: 6:09 PM
 */
global $post, $taxonomy_title, $taxonomy_name, $listing_view;

$listing_view = houzez_option('taxonomy_posts_layout');
$what_to_show = get_post_meta( $post->ID, 'fave_properties_sort', true );


//<!--edited-->
$fave_featured_listing = get_post_meta( $post->ID, 'fave_featured_listing', true );
$fave_featured_prop_no = get_post_meta( $post->ID, 'fave_featured_prop_no', true );
$fave_prop_no = get_post_meta( $post->ID, 'fave_prop_no', true );
//<!--edited-->

if( $listing_view == 'grid-view-3-col' ) {
    $listing_view_class = 'grid-view grid-view-3-col';
} else if( $listing_view == 'listing-style-3' ) {
    $listing_view_class = 'grid-view';
} else if( $listing_view == 'listing-style-2-grid-view' ) {
    $listing_view_class = 'grid-view listing-style-2-grid-view';
} else if( $listing_view == 'listing-style-2-grid-view-3-col' ) {
    $listing_view_class = 'grid-view grid-view-3-col listing-style-2-grid-view';
} else if( $listing_view == 'listing-style-2' ) {
    $listing_view_class = 'list-view listing-style-2';
} else {
    $listing_view_class = $listing_view;
}

// Title
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$taxonomy_title = $current_term->name;
$sticky_sidebar = houzez_option('sticky_sidebar');
$taxonomy_name = get_query_var( 'taxonomy' );

$taxonomy_layout = houzez_option('taxonomy_layout');
$taxonomy_num_posts = houzez_option('taxonomy_num_posts');

if( $taxonomy_layout == 'no-sidebar' ) {
    $content_classes = 'col-lg-12 col-md-12 col-sm-12';
} else if( $taxonomy_layout == 'left-sidebar' ) {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area container-contentbar';
} else if( $taxonomy_layout == 'right-sidebar' ) {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area pull-left container-contentbar';
} else {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area container-contentbar';
}

$number_of_prop = $taxonomy_num_posts;
if(!$number_of_prop){
    $number_of_prop = 9;
}
?>

<?php get_template_part('template-parts/properties-head'); ?>

<div class="row">
    <div class="<?php echo esc_attr($content_classes); ?>">
        <div id="content-area">
			

			<!--start featured property items-->
            <?php
            if($what_to_show == 'x_featured_first' || $what_to_show == 'x_rand_featured_first') { 
                global $wp_query, $paged;
                if ( is_front_page()  ) {
                    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
                }

                if( $fave_featured_listing != 'disable' ) {
                    $number_of_featured_prop = $fave_featured_prop_no;
                    if (!$number_of_featured_prop) {
                        $number_of_featured_prop = '4';
                    }

                    $prop_featured_args = array(
                        'post_type' => 'property',
                        'posts_per_page' => $number_of_featured_prop,
                        'paged' => $paged,
                        'post_status' => 'publish'
                    );
					

                    $prop_featured_args = apply_filters( 'houzez_featured_property_filter', $prop_featured_args );

                    $prop_featured_args = houzez_prop_sort($prop_featured_args);
                    $wp_query = new WP_Query($prop_featured_args);
					
					

                    if ($wp_query->have_posts()) : ?>
                        <div class="property-listing <?php echo esc_attr($listing_view); ?>">
                            <div class="row">

                                <?php
                                while ($wp_query->have_posts()) : $wp_query->the_post();
					

                                    get_template_part('template-parts/property-for-listing');

                                endwhile;
                                ?>

                            </div>
                        </div>
                        <hr>
                        <?php
                    endif;
                    wp_reset_query();
                }
            }
            ?>
            <!--end featured property items-->


            <!--start property items-->
            <div class="property-listing <?php echo esc_attr($listing_view_class); ?>">
                <div class="row">

                    <?php
					
					
					
					global $wp_query;
					
					
					
					$sort_args = array(
						'posts_per_page' => $number_of_prop,
						'order' => 'DESC',
						'post_status' => 'publish'
					);
					
                    $sort_args = houzez_prop_sort($sort_args);
					
					


                    
                    $args = array_merge( $wp_query->query_vars, $sort_args );

					
					

                    query_posts( $args );

                    if ( have_posts() ) :
                        while ( have_posts() ) : the_post();

                            if($listing_view == 'listing-style-3') {
                                get_template_part('template-parts/property-for-listing-v3');

                            } else if($listing_view == 'listing-style-2' || $listing_view == 'listing-style-2-grid-view' || $listing_view == 'listing-style-2-grid-view-3-col') {
                                get_template_part('template-parts/property-for-listing', 'v2');

                            } else {
                                get_template_part('template-parts/property-for-listing');
                            }

                        endwhile;
                        wp_reset_postdata();
                    else:
                        ?>
                        <h4><?php esc_html_e('Sorry No Result Found', 'houzez') ?></h4>
                        <?php
                    endif;
                    ?>

                </div>
            </div>
            <!--end property items-->

            <hr>

            <!--start Pagination-->
            <?php houzez_pagination( $wp_query->max_num_pages, $range = 2 ); ?>
            <!--start Pagination-->

        </div>
    </div><!-- end container-content -->

    <?php if( $taxonomy_layout != 'no-sidebar' ) { ?>
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 col-md-offset-0 col-sm-offset-3 container-sidebar <?php if( $sticky_sidebar['property_listings'] != 0 ){ echo 'houzez_sticky'; }?>">
        <?php get_sidebar('property'); ?>
    </div> <!-- end container-sidebar -->
    <?php } ?>

</div>


Буду благодарен за любую помощь. Спасибо
  • Вопрос задан
  • 37 просмотров
Пригласить эксперта
Ответы на вопрос 1
@mtseo Автор вопроса
Добился результата следующим образом:
<?php
/**
 * Common Taxonomy - Used by property taxonomies
 * Created by PhpStorm.
 * User: waqasriaz
 * Date: 08/01/16
 * Time: 6:09 PM
 */
global $post, $taxonomy_title, $taxonomy_name, $listing_view;

$listing_view = houzez_option('taxonomy_posts_layout');
$what_to_show = get_post_meta( $post->ID, 'fave_properties_sort', true );


//<!--edited-->
$fave_featured_listing = get_post_meta( $post->ID, 'fave_featured_listing', true );
$fave_featured_prop_no = get_post_meta( $post->ID, 'fave_featured_prop_no', true );
$fave_prop_no = get_post_meta( $post->ID, 'fave_prop_no', true );
//<!--edited-->

if( $listing_view == 'grid-view-3-col' ) {
    $listing_view_class = 'grid-view grid-view-3-col';
} else if( $listing_view == 'listing-style-3' ) {
    $listing_view_class = 'grid-view';
} else if( $listing_view == 'listing-style-2-grid-view' ) {
    $listing_view_class = 'grid-view listing-style-2-grid-view';
} else if( $listing_view == 'listing-style-2-grid-view-3-col' ) {
    $listing_view_class = 'grid-view grid-view-3-col listing-style-2-grid-view';
} else if( $listing_view == 'listing-style-2' ) {
    $listing_view_class = 'list-view listing-style-2';
} else {
    $listing_view_class = $listing_view;
}

// Title
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$taxonomy_title = $current_term->name;
$sticky_sidebar = houzez_option('sticky_sidebar');
$taxonomy_name = get_query_var( 'taxonomy' );

$taxonomy_layout = houzez_option('taxonomy_layout');
$taxonomy_num_posts = houzez_option('taxonomy_num_posts');

if( $taxonomy_layout == 'no-sidebar' ) {
    $content_classes = 'col-lg-12 col-md-12 col-sm-12';
} else if( $taxonomy_layout == 'left-sidebar' ) {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area container-contentbar';
} else if( $taxonomy_layout == 'right-sidebar' ) {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area pull-left container-contentbar';
} else {
    $content_classes = 'col-lg-8 col-md-8 col-sm-12 col-xs-12 list-grid-area container-contentbar';
}

$number_of_prop = $taxonomy_num_posts;
if(!$number_of_prop){
    $number_of_prop = 9;
}
?>

<?php get_template_part('template-parts/properties-head'); ?>

<div class="row">
    <div class="<?php echo esc_attr($content_classes); ?>">
        <div id="content-area">
			

			<!--start featured property items-->
            <?php
            if($what_to_show == 'x_featured_first' || $what_to_show == 'x_rand_featured_first') { 
                global $wp_query, $paged;
                if ( is_front_page()  ) {
                    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
                }

                if( $fave_featured_listing != 'disable' ) {
                    $number_of_featured_prop = $fave_featured_prop_no;
                    if (!$number_of_featured_prop) {
                        $number_of_featured_prop = '4';
                    }

                    $prop_featured_args = array(
                        'post_type' => 'property',
                        'posts_per_page' => $number_of_featured_prop,
                        'paged' => $paged,
                        'post_status' => 'publish'
                    );
					

                    $prop_featured_args = apply_filters( 'houzez_featured_property_filter', $prop_featured_args );

                    $prop_featured_args = houzez_prop_sort($prop_featured_args);
                    $wp_query = new WP_Query($prop_featured_args);
					
					

                    if ($wp_query->have_posts()) : ?>
                        <div class="property-listing <?php echo esc_attr($listing_view); ?>">
                            <div class="row">

                                <?php
                                while ($wp_query->have_posts()) : $wp_query->the_post();
					

                                    get_template_part('template-parts/property-for-listing');

                                endwhile;
                                ?>

                            </div>
                        </div>
                        <hr>
                        <?php
                    endif;
                    wp_reset_query();
                }
            }
            ?>
            <!--end featured property items-->


            <!--start property items-->
            <div class="property-listing <?php echo esc_attr($listing_view_class); ?>">
                <div class="row">

                    <?php
					
					
					
					global $wp_query;
					
					
					
					$sort_args = array(
						'posts_per_page' => $number_of_prop,
						'tax_query' => array(
							array(
								'taxonomy' => 'property_status',
								'field'    => 'id',
								'terms'    => '228',
								'paged' => $paged,
								'operator' => 'NOT IN'
							),
						),
						'order' => 'DESC',
						'post_status' => 'publish'
					);
					
                    $sort_args = houzez_prop_sort($sort_args);
					
                    
                    $args = array_merge( $wp_query->query_vars, $sort_args );
					

                    query_posts( $args );

                    if ( have_posts() ) :
                        while ( have_posts() ) : the_post();

                            if($listing_view == 'listing-style-3') {
                                get_template_part('template-parts/property-for-listing-v3');

                            } else if($listing_view == 'listing-style-2' || $listing_view == 'listing-style-2-grid-view' || $listing_view == 'listing-style-2-grid-view-3-col') {
                                get_template_part('template-parts/property-for-listing', 'v2');

                            } else {
                                get_template_part('template-parts/property-for-listing');
                            }

                        endwhile;
					
					
					
                        wp_reset_postdata();
                    else:
                        ?>
                        <h4><?php esc_html_e('Sorry No Result Found', 'houzez') ?></h4>
                        <?php
                    endif;
                    ?>

                </div>
            </div>
            <!--end property items-->
            
			<!--start property items-->
			<div class="property-listing <?php echo esc_attr($listing_view_class); ?>">
				<div class="row">

					<?php



					global $wp_query;



					$sort_args = array(
						'posts_per_page' => $number_of_prop,
						'tax_query' => array(
							array(
								'taxonomy' => 'property_status',
								'field'    => 'id',
								'paged' => $paged,
								'terms'    => '228'
							),
						),
						'order' => 'DESC',
						'post_status' => 'publish'
					);

					$sort_args = houzez_prop_sort($sort_args);


					$args = array_merge( $wp_query->query_vars, $sort_args );


					query_posts( $args );

					if ( have_posts() ) :
					while ( have_posts() ) : the_post();

					if($listing_view == 'listing-style-3') {
						get_template_part('template-parts/property-for-listing-v3');

					} else if($listing_view == 'listing-style-2' || $listing_view == 'listing-style-2-grid-view' || $listing_view == 'listing-style-2-grid-view-3-col') {
						get_template_part('template-parts/property-for-listing', 'v2');

					} else {
						get_template_part('template-parts/property-for-listing');
					}

					endwhile;
					wp_reset_postdata();
					else:
					?>
					<h4><?php esc_html_e('Sorry No Result Found', 'houzez') ?></h4>
					<?php
	endif;
					?>

				</div>
			</div>
			<!--end property items-->

            <hr>

            <!--start Pagination-->
            <?php houzez_pagination( $wp_query->max_num_pages, $range = 2 ); ?>
            <!--start Pagination-->

        </div>
    </div><!-- end container-content -->

    <?php if( $taxonomy_layout != 'no-sidebar' ) { ?>
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 col-md-offset-0 col-sm-offset-3 container-sidebar <?php if( $sticky_sidebar['property_listings'] != 0 ){ echo 'houzez_sticky'; }?>">
        <?php get_sidebar('property'); ?>
    </div> <!-- end container-sidebar -->
    <?php } ?>

</div>


Но, проблема в том, что я либо должен полностью исключить property_status с ID 228, либо у меня получается вывод внизу страницы, при втором проходе. Подскажите, есть ли возможность построить запрос так, чтобы все результаты с ID 228 просто отображались в конце всего списка (на последних страницах пагинации)?
Ответ написан
Ваш ответ на вопрос

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

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