Last active
June 3, 2020 14:39
-
-
Save djrmom/78ae0c74c9e63197c9ec1f4e9485022a to your computer and use it in GitHub Desktop.
facetwp add post_id to refresh
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 | |
/** adds the post_id to a variable passed during refresh **/ | |
add_action( 'wp_footer', function() { | |
if ( is_singular() ) : ?> | |
<script> | |
(function($) { | |
$(document).on('facetwp-refresh', function() { | |
FWP_HTTP.post_id = <?php echo get_the_ID(); ?> | |
}); | |
})(jQuery); | |
</script> | |
<?php endif; | |
}, 100 ); |
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 | |
/** access post_id in query args of facetwp template settings | |
** if using a visual query you'll first need to conver that to | |
** advanced query args **/ | |
$post_id = isset( $this->http_params['post_id'] ) ? $this->http_params['post_id'] : 0; // OR use if that doesn't work as expected - FWP()->facet->http_params['get'][ $post_id ] | |
if ( $post_id < 1 ) { | |
$post_id = get_the_id(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment