<?php


// Function to sort awards
function codewp_sort_awards($a, $b) {
    // Define your specific order for categories and types
    $categories_order = array('Best Actor', 'Best Actress', 'Best Picture');
    $types_order = array('Nominee', 'Winner');

    // Compare by year
    if ($a->awd_year != $b->awd_year) {
        return $a->awd_year - $b->awd_year;
    }

    // Compare by category
    $a_category_index = array_search($a->awd_sort_cat, $categories_order);
    $b_category_index = array_search($b->awd_sort_cat, $categories_order);
    if ($a_category_index != $b_category_index) {
        return $a_category_index - $b_category_index;
    }

    // Compare by type
    $a_type_index = array_search($a->awd_type, $types_order);
    $b_type_index = array_search($b->awd_type, $types_order);
    if ($a_type_index != $b_type_index) {
        return $a_type_index - $b_type_index;
    }

    return 0;
}

// Fetch and sort awards
function codewp_fetch_and_sort_awards() {
    // Fetch awards
    $args = array('post_type' => 'awards', 'numberposts' => -1);
    $awards = get_posts($args);

    // Sort awards
    usort($awards, 'codewp_sort_awards');

    return $awards;
}

$sorted_awards = codewp_fetch_and_sort_awards();
?>