Making WordPress.org


Ignore:
Timestamp:
06/13/2019 10:31:41 PM (5 years ago)
Author:
coffee2code
Message:

Jobs: Sort front page listing by job categories according to recency of their most recently posted jobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/jobs.wordpress.net/public_html/wp-content/themes/jobswp/content-home.php

    r88 r8950  
    66if ( $job_categories ) :
    77
     8// Groups jobs according to job category.
     9foreach ( $job_categories as $i => $category ) {
     10    $job_category_jobs[ $category->slug ] = Jobs_Dot_WP::get_jobs_for_category( $category );
     11    $latest_post = $job_category_jobs[ $category->slug ][0];
     12    // Add key for sorting.
     13    $job_categories[ $i ]->latest_post_date = $latest_post ? $latest_post->post_date : '0';
     14}
     15
     16// Sort job categories according to recency of latest post.
     17$job_categories = wp_list_sort( $job_categories, [ 'latest_post_date' => 'DESC', 'name' => 'ASC' ] );
     18
     19// Display the categories and their jobs.
    820foreach ( $job_categories as $category ) {
    9     $posts = Jobs_Dot_WP::get_jobs_for_category( $category );
     21    $posts = $job_category_jobs[ $category->slug ];
    1022
    1123    //Display the name of the category, whether there are jobs or not
Note: See TracChangeset for help on using the changeset viewer.