Plugin Directory

Changeset 3245727


Ignore:
Timestamp:
02/24/2025 12:09:27 PM (13 months ago)
Author:
recruitly
Message:

Added optional job_county filter to the [recruitly_jobs] shortcode for more flexible job listings.

Location:
recruitly/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • recruitly/trunk

    • Property svn:ignore set to
      .idea
  • recruitly/trunk/admin/includes/shortcodes.php

    r3235770 r3245727  
    5454
    5555/**
    56  * Lists all jobs with pagination support
    57  */
    58 function recruitly_wordpress_job_listing_shortcode()
    59 {
    60 
    61     //recruitly_wordpress_insert_post_type();
     56 * Lists all jobs with pagination support and optional shortcode attributes.
     57 */
     58function recruitly_wordpress_job_listing_shortcode($atts)
     59{
     60    // Extract shortcode attributes and set defaults
     61    $atts = shortcode_atts(
     62        array(
     63            'job_county' => '', // Default: no county filter
     64        ),
     65        $atts,
     66        'recruitly_jobs'
     67    );
    6268
    6369    global $wp_query;
    64 
    6570    $temp = $wp_query;
    6671
     72    // Handle pagination
    6773    if (get_query_var('paged')) {
    68 
    6974        $paged = get_query_var('paged');
    70 
    7175    } elseif (get_query_var('page')) {
    72 
    7376        $paged = get_query_var('page');
    74 
    7577    } else {
    76 
    7778        $paged = 1;
    78 
    79     }
    80 
     79    }
     80
     81    // Base query arguments
    8182    $args = array(
    8283        'post_type' => RECRUITLY_POST_TYPE,
     
    8889    );
    8990
    90 
     91    // Check for search parameters and nonce validation
    9192    if (isset($_GET['recruitly_jobsearch_nonce'])
    9293        && wp_verify_nonce($_GET['recruitly_jobsearch_nonce'], 'recruitly_jobsearch_action')
    9394        && isset($_GET['job_search'])) {
    9495
    95         //Escape Output
     96        // Escape and sanitize input
    9697        if (isset($_GET['job_type'])) $job_type = htmlspecialchars(sanitize_text_field(wp_unslash($_GET['job_type'])));
    9798        if (isset($_GET['job_sector'])) $job_sector = htmlspecialchars(sanitize_text_field(wp_unslash($_GET['job_sector'])));
     
    100101        if (isset($_GET['job_search'])) $q = htmlspecialchars(sanitize_text_field(wp_unslash($_GET['job_search'])));
    101102
     103        // Add search query if provided
    102104        if ($q) {
    103105            $args['s'] = $q;
    104106        }
    105107
     108        // Initialize tax_query and meta_query arrays
    106109        $args['tax_query'] = array('relation' => 'AND');
    107         //Tag is a meta query
     110        $args['meta_query'] = array('relation' => 'AND');
     111
     112        // Job Tag (meta query)
    108113        if ($job_tag) {
    109             $args['meta_query'] = array('relation' => 'AND');
    110114            $args['meta_query'][] = array(
    111                 'value' => $job_tag
    112             );
    113         }
    114 
    115         //Job Type, Sector and City are Taxonomy Queries
     115                'key' => 'job_tag', // Assuming 'job_tag' is the meta key
     116                'value' => $job_tag,
     117                'compare' => '='
     118            );
     119        }
     120
     121        // Job Type, Sector, City (taxonomy queries)
    116122        if ($job_type) {
    117123            $args['tax_query'][] = array(
     
    121127            );
    122128        }
    123 
    124129        if ($job_sector) {
    125130            $args['tax_query'][] = array(
     
    129134            );
    130135        }
    131 
    132136        if ($job_city) {
    133137            $args['tax_query'][] = array(
     
    137141            );
    138142        }
    139 
    140     }
    141 
     143    }
     144
     145    // Add job_county filter from shortcode attributes
     146    if (!empty($atts['job_county'])) {
     147        $args['tax_query'][] = array(
     148            'taxonomy' => 'jobcounty',
     149            'field' => 'slug',
     150            'terms' => sanitize_text_field($atts['job_county']) // Sanitize the input
     151        );
     152    }
     153
     154    // Execute the query
    142155    $wp_query = new WP_Query($args);
     156
     157    // Start output buffering
    143158    ob_start();
    144159    get_recruitly_template('job-listing.php');
    145160    wp_reset_query();
    146161    $wp_query = $temp;
     162
     163    // Return the buffered content
    147164    return ob_get_clean();
    148165}
  • recruitly/trunk/readme.txt

    r3235770 r3245727  
    44Requires at least: 4.5
    55Tested up to: 6.7.1
    6 Stable tag: 2.0.24
     6Stable tag: 2.0.25
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    113113* Fix shortcode search filter issue.
    114114
     115= 2.0.25 =
     116* Added optional job_county filter to the [recruitly_jobs] shortcode for more flexible job listings.
     117
    115118== Upgrade Notice ==
    116119
  • recruitly/trunk/recruitly.php

    r3235770 r3245727  
    44Plugin URI: https://recruitly.io
    55Description: Recruitly job board integration.
    6 Version: 2.0.24
     6Version: 2.0.25
    77Author: Recruitly
    88Author URI: https://recruitly.io
Note: See TracChangeset for help on using the changeset viewer.