Registering FacetWP facets with PHP

If possible I always try to register things with PHP rather than using the WordPress interface.

It means that version control can be used and therefore anyone using the code automatically has the registered items.

One example of this is FacetWP. Here is how to register a facet with FacetWP using PHP.

<?php
/**
 * Registers the Facets with FacetWP.
 *
 * @param array  $facets The current array of registered facets.
 * @return array $facets The modified array of registered facets.
 */
function hd_utility_add_job_facets( $facets ) {

	// add the job industry facet.
	$facets['job_industry'] = array(
		'name'            => 'job_industry',
		'label'           => __( 'Job Industry', 'hd-utility' ),
		'type'            => 'checkboxes',
		'source'          => 'tax/hd_job_industry',
		'parent_term'     => '', 
		'modifier_type'   => 'off', 
		'modifier_values' => '', 
		'hierarchical'    => 'yes', 
		'show_expanded'   => 'no', 
		'ghosts'          => 'no', 
		'preserve_ghosts' => 'no', 
		'operator'        => 'or', 
		'orderby'         => 'count', 
		'count'           => '-1', 
		'soft_limit'      => '10',
	);

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

}

add_filter( 'facetwp_facets', 'hd_utility_add_job_facets', 10, 1 );