Add DDHH_JM_Archive class to modify job archive queries. Ensures Elementor Loop Grid displays only published jobs sorted by date (newest first) with no pagination limit. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Archive class
|
|
*
|
|
* Handles job archive query modifications for Elementor template integration
|
|
*
|
|
* @package DDHH_Job_Manager
|
|
*/
|
|
|
|
// Exit if accessed directly.
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
/**
|
|
* Archive class
|
|
*/
|
|
class DDHH_JM_Archive {
|
|
|
|
/**
|
|
* Initialize hooks
|
|
*/
|
|
public static function setup_hooks() {
|
|
// Modify archive query for published jobs
|
|
add_action( 'pre_get_posts', array( __CLASS__, 'modify_archive_query' ), 10 );
|
|
}
|
|
|
|
/**
|
|
* Modify job archive query to show only published jobs
|
|
*
|
|
* @param WP_Query $query The WordPress Query object.
|
|
*/
|
|
public static function modify_archive_query( $query ) {
|
|
// Only modify job_offer archive queries on the frontend
|
|
if ( is_admin() || ! $query->is_main_query() ) {
|
|
return;
|
|
}
|
|
|
|
// Check if this is a job_offer archive
|
|
if ( ! $query->is_post_type_archive( 'job_offer' ) ) {
|
|
return;
|
|
}
|
|
|
|
// Set query parameters for published jobs
|
|
$query->set( 'post_status', 'publish' );
|
|
$query->set( 'orderby', 'date' );
|
|
$query->set( 'order', 'DESC' );
|
|
$query->set( 'posts_per_page', -1 );
|
|
}
|
|
}
|