Last active
September 18, 2019 14:01
-
-
Save mbootsman/e8bcf65286a90a01a89423d36f98006b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Facetwp preselect */ | |
add_filter( 'facetwp_preload_url_vars', 'nstrm_filter_facets' ); | |
function nstrm_filter_facets( $url_vars ) { | |
// get post uri | |
$uri = FWP()->helper->get_uri(); | |
// get post id | |
$post_id = nostromo_get_post_id_by_post_name( $uri ); | |
if ( $post_id ) { | |
// specialisms | |
$specialisms = get_field( 'specialisms', $post_id ); | |
if ( ! empty( $specialisms ) && ( $specialisms[ 'specialism' ] != '' ) ) { | |
$specialisms_array = Array(); | |
foreach ( $specialisms[ 'specialism' ] as $specialism ) { | |
$specialisms_array[] = $specialisms[ 'value' ]; | |
} | |
if ( ! empty ( $specialisms_array ) ) { | |
$url_vars[ 'specialisms' ] = $specialisms_array; | |
// Hide this facet, like a lion in the grass | |
add_action( 'wp_footer', function() { ?> | |
<style>.facetwp-facet-specialisms { display: none }</style> | |
<?php } ); | |
} | |
} | |
// level | |
$level = get_field( 'filter_level', $post_id ); | |
if ( ! empty( $level ) && ( $level[ 'level' ] != '' ) ) { | |
$url_vars[ 'level' ] = array( $level[ 'level' ] ); | |
// Hide this facet, like a lion in the grass | |
add_action( 'wp_footer', function() { ?> | |
<style>.facetwp-facet-level { display: none }</style> | |
<?php } ); | |
} | |
} | |
// only return the url vars if they have been filled | |
if ( ! empty( $url_vars ) ) { | |
return $url_vars; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment