diff --git a/wp-content/themes/homeproz/archive-agent.php b/wp-content/themes/homeproz/archive-agent.php index 05887ff7..53e973ea 100644 --- a/wp-content/themes/homeproz/archive-agent.php +++ b/wp-content/themes/homeproz/archive-agent.php @@ -12,31 +12,33 @@ if (!defined('ABSPATH')) { get_header(); -// Query active agents, ordered by agent_order then title -$agents_query = new WP_Query([ +// Query all published agents, then filter disabled and sort by order +$all_agents = get_posts([ 'post_type' => 'agent', 'posts_per_page' => -1, 'post_status' => 'publish', - 'meta_query' => [ - 'relation' => 'OR', - // Agent is not disabled - [ - 'key' => 'agent_disabled', - 'value' => '1', - 'compare' => '!=', - ], - // Or agent_disabled field doesn't exist yet - [ - 'key' => 'agent_disabled', - 'compare' => 'NOT EXISTS', - ], - ], - 'meta_key' => 'agent_order', - 'orderby' => [ - 'meta_value_num' => 'ASC', - 'title' => 'ASC', - ], ]); + +// Filter out disabled agents and add sorting data +$agents_data = []; +foreach ($all_agents as $agent) { + $disabled = get_field('agent_disabled', $agent->ID); + if ($disabled) continue; + + $order = get_field('agent_order', $agent->ID); + $agents_data[] = [ + 'post' => $agent, + 'order' => $order ? (int) $order : 10, // Default to 10 if not set + ]; +} + +// Sort by order, then by title +usort($agents_data, function($a, $b) { + if ($a['order'] !== $b['order']) { + return $a['order'] - $b['order']; + } + return strcmp($a['post']->post_title, $b['post']->post_title); +}); ?>
@@ -51,24 +53,26 @@ $agents_query = new WP_Query([
- have_posts()) : ?> +
- have_posts()) : $agents_query->the_post(); - $agent_id = get_the_ID(); + ID; $agent_phone = get_field('agent_phone', $agent_id); $agent_email = get_field('agent_email', $agent_id); $agent_title = get_field('agent_title', $agent_id); $agent_short_bio = get_field('agent_short_bio', $agent_id); + $agent_permalink = get_permalink($agent_id); // Get featured image $agent_photo_id = get_post_thumbnail_id($agent_id); $agent_photo_url = $agent_photo_id ? wp_get_attachment_image_url($agent_photo_id, 'medium_large') : ''; ?> - +

No team members to display at this time.

- -