feat(05-01): create archive query helper for Elementor integration
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>
This commit is contained in:
@@ -36,6 +36,7 @@ require_once DDHH_JM_PLUGIN_DIR . 'includes/class-pages.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-dashboard.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-access-control.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-notifications.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-archive.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-admin-ui.php';
|
||||
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-ddhh-job-manager.php';
|
||||
|
||||
|
||||
48
includes/class-archive.php
Normal file
48
includes/class-archive.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,9 @@ class DDHH_JM_Job_Manager {
|
||||
// Initialize notifications
|
||||
add_action( 'init', array( 'DDHH_JM_Notifications', 'setup_hooks' ) );
|
||||
|
||||
// Initialize archive query helper
|
||||
add_action( 'init', array( 'DDHH_JM_Archive', 'setup_hooks' ) );
|
||||
|
||||
// Initialize admin UI enhancements (admin-only)
|
||||
if ( is_admin() ) {
|
||||
add_action( 'init', array( 'DDHH_JM_Admin_UI', 'setup_hooks' ) );
|
||||
|
||||
Reference in New Issue
Block a user