recpress_job_listings_query_args

Filters arguments passed to the query on the job listings shortcode.


Parameters

Example

This is an example of how RecPress core uses this function to amend the job listings query, to filter the jobs by job categories, passed to the shortcode function in the categories parameter.

<?php
/**
 * Maybe adds category tax queries to the job listing query args.
 *
 * @param  array $args  The current job listing shortcode query args.
 * @param  array $attrs The array of args passed to the shortcode.
 *
 * @return array $args The maybe modified query args.
 */
function recpress_add_category_job_listings_query_args( $args, $attrs ) {

	// if we have no category attribute.
	if ( empty( $attrs['categories'] ) ) {
		return $args; // do nothing.
	}

	// turn the category args into an array.
	$categories = explode( '|', $attrs['categories'] );

	// if categories is for some reason empty.
	if ( empty( $categories ) ) {
		return $args; // do nothing.
	}

	// loop through each category.
	foreach ( $categories as $category ) {

		// add this category to the tax query array.
		$args['tax_query']['categories'][$category] = [
			'taxonomy' => 'job_listing_category',
			'field'    => 'slug',
			'terms'    => sanitize_text_field( $category ),
		];

	}

	// return the maybe modified args.
	return $args;

}

add_filter( 'recpress_job_listings_query_args', 'recpress_add_category_job_listings_query_args', 10, 2 );