Skip to content

Instantly share code, notes, and snippets.

@ahegyes
ahegyes / gist:4ecfbc4275ffbf38543dd6d71015285e
Created May 26, 2021 08:50
FacetWP fuzzy autocomplete
add_filter( 'query', function( $query ) {
if ( false !== strpos( $query, 'facet_display_value LIKE' ) ) {
preg_match( "/LIKE '%(.*?)%'/s", $query, $matches );
$keywords = $matches[1];
if ( ! empty( $keywords ) ) {
$old_where = "facet_display_value LIKE '%$keywords%'";
$new_where = array();
$keywords_boom = explode( ' ', $keywords );
@djrmom
djrmom / custom-hooks.php
Created September 14, 2020 13:45
facetwp always ignore archive query
<?php
/** always ignore archive query as main query for facet **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@jchristopher
jchristopher / tmp.php
Created March 27, 2020 16:41
Check whether a SearchWP Engine has non-WP_Post Sources
<?php
// Check whether a SearchWP Engine has non-WP_Post Sources.
$engine = new \SearchWP\Engine( 'supplemental' );
$sources = array_keys( $engine->get_sources() );
$non_wp_post_sources = array_filter( $sources, function( $source ) {
return 0 !== strpos( $source, 'post' . SEARCHWP_SEPARATOR );
} );
@djrmom
djrmom / custom-hooks.php
Created October 12, 2018 18:49
facetwp woocommerce layout builder
<?php
/** layout builder output for woocommerce custom fields **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 0 === strpos( $value, 'woo/' ) ) {
$field_key = substr( $value, 4 );
if ( 'price' == $field_key ) {
@mgibbs189
mgibbs189 / functions.php
Last active April 17, 2018 11:14
FacetWP - pass ACF data into template
<?php
/**
* To access the data within the "Query Arguments" box, use:
* $this->http_params['choose_city']
*/
add_action( 'wp_footer', function() {
$choose_city = get_field( 'choose_city' );
?>
@mgibbs189
mgibbs189 / test.html
Created March 28, 2018 16:31
Manually replace sort box with fSelect
<link href="path/to/fSelect.css" rel="stylesheet" type="text/css">
<script src="path/to/fSelect.js">
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-sort-select').fSelect();
});
})(jQuery);
</script>
@djrmom
djrmom / custom-hooks.php
Last active September 26, 2020 15:15
facetwp only products
<?php
/* only filter product queries */
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'product_query' != $query->get( 'wc_query' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
<?php
add_filter( 'facetwp_filtered_post_ids', 'car_zero_priced_last', 10, 2);
function car_zero_priced_last( $post_ids, $class ) {
if (!isset($class->ajax_params['http_params']['get']['fwp_sort'])) {
return $post_ids;
}
if (isset($class->ajax_params['http_params']['get']['fwp_sort']) && $class->ajax_params['http_params']['get']['fwp_sort'] != 'price_asc') {
return $post_ids;
@djrmom
djrmom / custom-hooks.php
Last active February 16, 2018 21:01
facetwp force query args
<?php
/** to use this make sure all queries to be used
** for facets have 'facetwp' => true in query args, including the
** query args setting in a facetwp template
**/
// add 'facetwp' => false anytime it is not already set
add_action( 'pre_get_posts', function( $query ) {
if ( ! isset( $query->query_var['facetwp'] ) ) {
$query->set( 'facetwp', false );
@swissspidy
swissspidy / language-updates-table.php
Last active April 4, 2020 11:20
Display a table with available translation updates on the WordPress update screen
<?php
/**
* Plugin Name: Translation Updates Table
*
* @author Pascal Birchler <pascal@required.ch>
* @license GPL2+
*/
/**
* Displays a table with available translation updates.