Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created November 16, 2017 16:02
facetwp hide/show map
<?php
/**
* initially hide the map facet ( .facetwp-facet-map ) and toggle visibility on click of .show_map
*
*/
add_action( 'wp_head', function() { ?>
<style>
.facetwp-facet-map {display: none; }
</style>
<script>
@djrmom
djrmom / custom-hooks.php
Last active April 19, 2018 16:08
facetwp filter html
<?php
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'my_facet' == $params['facet']['name'] ) { // change 'my_facet' to name of your facet
$output = str_replace ( '</select>' , '</select><button onclick="FWP.refresh()">>></button>' , $output );
}
return $output;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Created November 16, 2017 16:02
facetwp selected facets
<?php
$selected_alpha = '';
if ( isset( FWP()->facet->facets['titles']['selected_values'] ) ) {
$alpha = FWP()->facet->facets['titles']['selected_values'];
$selected_alpha = array_shift( $alpha );
}
while ( have_posts() ) : the_post(); ?>
<div id="downloads">
@djrmom
djrmom / custom-hooks.php
Created November 16, 2017 16:02
facetwp change autocomplete button text
<?php
/**
* replace "Update" for search button with different text
* change 'autocomplete_facet' to the name of your facet
* Note that this text is also translation ready and could be
* modified using internationalization functions as well
*/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'autocomplete_facet' == $params['facet']['name'] ) {
@djrmom
djrmom / custom-hooks.php
Created November 21, 2017 18:46
facetwp index parents
<?php
add_filter( 'facetwp_index_row', function ( $params, $class ) {
if ( 'my_facet' == $params['facet_name'] ) { // change 'my_facet' to facet name
if ( 0 !== $params['depth'] ) {
// lookup parent terms
$ancestors = get_ancestors( $params['facet_name'], 'name_of_taxonomy', 'taxonomy' ); // 'name_of_taxonomy' to name of taxonomy
$starting_depth = $params['depth'];
foreach ( $ancestors as $ancestor ) {
$term = get_term( $ancestor, 'name_of_taxonomy' ); // 'name_of_taxonomy' to name of taxonomy
@djrmom
djrmom / custom-hooks.php
Created December 4, 2017 18:15
facetwp search placeholder
<?php
add_filter( 'facetwp_facet_render_args', function( $args) {
if ( 'my_search_facet' == $args['facet']['name'] ) { // change my_search_facet to name of your facet
$args['facet']['placeholder'] = 'Something';
}
return $args;
} );
@djrmom
djrmom / custom-hooks.php
Last active August 25, 2020 16:00
facetwp index checkbox saved as array
<?php
/** index a serialized checkbox
** run reindex after adding code to your site
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_facet' == $params['facet_name'] ) { // change my_facet to name of your facet
$values = maybe_unserialize( $params['facet_value'] );
if ( is_array( $values ) && ! empty( $values ) ) {
foreach ( $values as $value ) {
@djrmom
djrmom / custom-hooks.php
Created December 5, 2017 19:15
facetwp divi column js
<?php
/**
* updates et_pb_column_single for divi on facet load
*/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if ( $( '.et_section_specialty' ).length ) {
$( '.et_section_specialty' ).each( function() {
@djrmom
djrmom / custom-hooks.php
Last active April 19, 2018 16:22
facetwp listings not ordered by featured
<?php
// check for job_listings archive and don't use the query unless it is using menu_order
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( isset( $query->query_vars['post_type'] ) && 'job_listing' == $query->query_vars['post_type']
&& ( ! isset( $query->query_vars['taxonomy'] ) || '' == $query->query_vars['taxonomy'] ) ) {
if ( isset( $query->query_vars['order_by']['menu_order'] ) ) {
return true;
} else {
return false;
@djrmom
djrmom / custom-hooks.php
Last active December 12, 2017 18:55
facetwp change author display
<?php
// re-index your facets after adding this code
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'author' == $params['facet_name'] ) {
$user = get_user_by( 'login', $params['facet_display_value'] );
if ( false !== $user ) {
$params['facet_display_value'] = $user->last_name . ', ' . $user->first_name
}
}
return $params;