2015-03-25 7 views
0

Активная среда, где следующий будет находиться: http://test-hdwg.pantheon.io/projects/Добавление дополнительных слоев заказа к аргументу WP_Query

Столкнулся с небольшой PHP WP_Query() фильтрации задач, которые я хотел бы знать, как лучший подход. Клиент хотел, чтобы отфильтровать результаты WP_Query на основе следующего (Ламене письменного) алгоритма с использованием значения Advanced Пользовательские поля (АКФ) в WordPress (4.1.1) среды:

If the query produces multiple results... { 
    sort the results by ACF field “project_year_end” { 
    if the field contains “present”, filter these items first { 
     if multiple results, then { 
     further sort by the field “project_year_start” value {} 
     } 
    } 
    else if, sort those without “present” afterwards by the “project_year_end” value { 
     if multiple results for a single value (ex: 2015), then { 
     further sort by “project_year_start” { } 
     } 
    } 
    } 
} 

в настоящее время, шаблон (PHP), который должен включать этот отфильтрованный запрос построен следующим образом:

<?php /* Template Name: Projects */ ?> 
<?php get_header(); ?> 

    <main id="primary" class="content-area"> 
     <div class="jumbotron"> 
     <div class="row"> 
      <div class="intro"><?php the_field('projects_heading') ?></div> 
     </div> 
     </div> 
     <div class="projects"> 
     <div class="row project-list"> 
      <div class="column-wrapper"> 
<?php 
    $args = array (
    'post_type'  => 'project', // target the post-type for projects 
    'post_per_page' => '20',  // display (at max) (x) at once 
    'nopaging'  => true,  // disable automatic pagination 
    'order'   => 'ASC',  // display order = ascending 
    'orderby'  => 'title' // organized based on the the_title() of the post 
); 
    $projects = new WP_Query($args); 
    if ($projects->have_posts()) { 
?> 
      <div class="project-listing"> 
<?php while ($projects->have_posts()) { 
    $projects->the_post(); 
?> 
       <div class="columns ui-listing-block"> 
       <hr/> 
       <h2><?php the_field('project_title') ?></h2> 
<?php if(have_rows('project_date_range')): ?> 
       <span> 
<?php while(have_rows('project_date_range')): the_row(); ?> 
<?php the_sub_field('project_year_start'); ?>-<?php the_sub_field('project_year_end'); ?> 
<?php endwhile; ?> 
       </span> 
<?php endif; ?> 
       <?php echo project_excerpt(); ?> 
       <a href="<?php the_permalink(); ?>" title="Learn more about the project: <?php the_field('project_title') ?>" class="button postfix">Learn More</a> 
       </div> 
<?php } ?> 
      </div> 
<?php } else { ?> 
      <p>No Projects Available.</p> 
<?php } wp_reset_postdata(); ?> 
      </div> 
     </div> 
     </div> 
    </main> 
<?php get_footer(); ?>` 

Любая помощь будет принята с благодарностью.

+0

Единственный разумный способ, который я вижу здесь, это использовать 'usort()' –

+0

Спасибо, Пейтер, я начал исследовать usort(). Я ценю ваш вклад. – Joey

ответ

Смежные вопросы