Skip to content

Instantly share code, notes, and snippets.

View felipeelia's full-sized avatar

Felipe Elia felipeelia

View GitHub Profile
@felipeelia
felipeelia / elasticpress-custom-query-boosting.php
Created July 5, 2023 17:11
Add boosting to ElasticPress queries. THIS IS NOT COMPLETE YET.
<?php
/**
* Plugin Name: ElasticPress - Custom Query Boosting
* Description: Add Boosting query to ElasticPress
* Version: 1.0.0
* Author: 10up | Felipe Elia
* Author URI: https://10up.com/
* Text Domain: elasticpress-custom-query-boosting
* Domain Path: /languages
*
@felipeelia
felipeelia / felipeelia-classifai.php
Created June 24, 2023 22:55
Compatibility layer between the ClassifAI plugin and Polylang
<?php
/**
* Plugin Name: ClassifAI and Polylang
* Description: Compatibility layer between the ClassifAI plugin and Polylang
* Version: 1.0.0
* Author: Felipe Elia
* Author URI: https://felipeelia.dev/
* Text Domain: felipeelia-classifai
* Domain Path: /languages
*
@felipeelia
felipeelia / elasticpress-autosuggest-view-all-results.js
Created January 23, 2023 21:33
Add a "See All X Results" item to the autosuggest panel
let autosuggestTotal = 0;
const autosuggestDataFilter = (data) => {
autosuggestTotal = data?.hits?.total || 0;
return data;
}
wp.hooks.addFilter('ep.Autosuggest.data', 'myTheme/autosuggestDataFilter', autosuggestDataFilter);
const autosuggestListHTMLFilter = (listHTML, options, input) => {
const allUrl = new URL(input.form.action);
@felipeelia
felipeelia / elasticpress-sync-attachments.php
Created December 8, 2022 18:23
[ElasticPress] Sync and search for Media (attachment) posts in WordPress
<?php
/**
* Sync and search for Media (attachment) posts in WordPress.
* It is NOT to be used with the ElasticPress's Documents feature
*/
/**
* Add the attachment post type to be indexable and searchable
*
* @param array $post_types Post types
@felipeelia
felipeelia / global-snippets.code-snippets
Created September 22, 2022 15:24
Visual Studio Code snippet to add co-authors to commits
{
// Hit ctrl+P and select Snippets: Configure User Snippets
// New Global Snippets file
// Add `global-snippets` as the name and copy this file contents in it
// Go to the commit box, start typing `git_co_authored_by`, hit ctrl+space and select this snippet
"Git Co-authored-by": {
"prefix": "git_co_authored_by",
"body": [
"",
"",
@felipeelia
felipeelia / elasticpress-search-thumbnail-exists.php
Created March 24, 2022 11:26
Change the ElasticPress search query to match only content with a thumbnail set.
<?php
/**
* Since ElasticPress 4.0, thumbnails are indexed in a separate field.
*/
add_filter(
'ep_post_formatted_args',
function ( $formatted_args ) {
if ( empty( $_GET['has_image'] ) ) {
return $formatted_args;
}
@felipeelia
felipeelia / elasticpress-dynamic-sync-debug.php
Created March 6, 2022 19:29
Set of functions to help debugging ElasticPress dynamic sync requests
<?php
/**
* This is a set of functions that can be used to debug
* the dynamic sync made by ElasticPress
*
* phpcs:disable WordPress.PHP.DevelopmentFunctions -- Reason: the whole purpose of the file is to use error_log().
*
* @package ElasticPress_Custom
*/
@felipeelia
felipeelia / elasticpress-partial-matches-on-woocommerce-skus.php
Created February 17, 2022 13:31
Add to ElasticPress the capability to partially match a WooCommerce SKU.
<?php
/**
* Add the ngram analyzer if not added yet by autosuggest.
*
* @param array $mapping The mapping array.
* @return array
*/
function ep_custom_add_edge_ngram_analyzer( $mapping ) {
if ( ! @isset( $mapping['settings']['analysis']['analyzer']['edge_ngram_analyzer'] ) ) {
$mapping['settings']['analysis']['analyzer']['edge_ngram_analyzer'] = array(
@felipeelia
felipeelia / elasticpress-woocommerce-customer-order-csv-export.php
Created February 3, 2022 19:31
Add compatibility between ElasticPress and WooCommerce Customer/Order/Coupon Export
<?php
/**
* Add compatibility between ElasticPress and WooCommerce Customer/Order/Coupon Export.
*/
add_filter(
'ep_sync_taxonomies',
function ( $taxonomies ) {
if ( class_exists( '\SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler' ) ) {
$taxonomies[] = \SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler::TAXONOMY_NAME_ORDERS;
@felipeelia
felipeelia / elasticpress-decay-adjustments.php
Created January 21, 2022 14:23
ElasticPress decay adjustments
<?php
/*
* Part of this comment in the ElasticPress repository
*
* @see https://github.com/10up/ElasticPress/issues/2073#issuecomment-776155310
*/
add_filter( 'epwr_boost_mode', function() { return 'multiply'; } );
add_filter( 'epwr_offset', function() { return '15d'; } );
add_filter( 'epwr_scale', function() { return '30d'; } );
add_filter( 'epwr_decay', function() { return 0.5; } );