Skip to content

Instantly share code, notes, and snippets.

View felipeelia's full-sized avatar

Felipe Elia felipeelia

View GitHub Profile
@felipeelia
felipeelia / elasticpress-search-algorithm-4.0.php
Created December 10, 2021 19:28
ElasticPress 4.0.0 Search Algorithm
<?php
/**
* These functions can be used by ElasticPress 3.5.5+ users wanting to
* use the search algorithm introduced as default in EP 4.0
*/
/**
* Change the search algorithm to the one introduced in ElasticPress 4.0.
*
* @param array $query Current query
@felipeelia
felipeelia / log-db-queries-wordpress.php
Created September 25, 2021 13:03
Log DB Queries for WordPress
<?php
namespace TenUp_QueryLog;
function log_queries( $query ) {
if ( ! preg_match( '/^\s*(create|alter|truncate|drop|insert|delete|update|replace)\s/i', $query ) ) {
return $query;
}
// Not interested in any operations with transients
@felipeelia
felipeelia / elasticpress-related-posts-adjustments.php
Last active July 29, 2022 13:19
Tweaks for ElasticPress's Related Posts Features
@felipeelia
felipeelia / ep-add-cross-fields.php
Last active December 10, 2021 19:25
ElasticPress: Make Elasticsearch search for the string in different fields
<?php
/**
* Add a cross_field type clause to the ES query, so it searches for terms
* in different fields.
*
* @param array $query Current query
* @param array $args Query variables
* @param string $search_text Search text
* @param array $search_fields Search fields
@felipeelia
felipeelia / ngrok.php
Last active September 1, 2022 23:41
WordPress MU Plugin to have it working with ngrok.io
<?php
/**
* Place this file in the wp-content/mu-plugins directory and run ngrok with
* `ngrok http http://<local_url> --host-header=<local_url>`
*/
$ngrok_url = '<id>.ngrok.io';
define( 'WP_HOME', 'http://' . $ngrok_url );
define( 'WP_SITEURL', 'http://' . $ngrok_url );
@felipeelia
felipeelia / ep-product-variation-titles.php
Last active March 18, 2021 17:50
ElasticPress - Index product variation titles into the parent product
<?php
// Create a new field with product variation titles.
add_filter(
'ep_prepare_meta_data',
function( $post_meta, $post ) {
if ( 'product' !== get_post_type( $post ) ) {
return $post_meta;
}
@felipeelia
felipeelia / fb-instagram-oembed-time.sql
Created October 21, 2020 18:47
[WordPress] Bump FB and Instagram oembed time
UPDATE
`wp_postmeta` pm
SET meta_value = 1924905600
WHERE meta_key IN
(
SELECT * FROM
(
SELECT REPLACE(meta_key, '_oembed_', '_oembed_time_')
FROM `wp_postmeta`
WHERE meta_key LIKE '_oembed_%' AND ( meta_value LIKE '%id="fb-root"%' OR meta_value LIKE '%class="instagram-media"%' )
@felipeelia
felipeelia / elasticpress-remove-terms-from-facet-widget.php
Created October 12, 2020 13:30
Exclude some terms form the ElasticPress Facets Widget Filter
<?php
// Exclude some terms form the ElasticPress Facets Widget Filter
add_action(
'pre_get_terms',
function ( $wp_term_query ) {
global $wp_query;
if ( ! $wp_query->get( 'ep_facet', false ) ) {
return false;
}
@felipeelia
felipeelia / elasticpress-add-meta-fields-to-search.php
Last active June 11, 2021 00:55
ElasticPress: Add specific post meta to search fields
<?php
add_filter(
'ep_weighting_configuration_for_search',
function( $weighting_config ) {
global $wpdb;
$post_meta = get_transient( 'custom_ep_distinct_post_meta' );
if ( ! $post_meta ) {
$post_meta = $wpdb->get_col(
"SELECT DISTINCT meta_key
@felipeelia
felipeelia / elasticpress-remove-some-meta.php
Last active April 6, 2022 19:33
Remove some meta fields from the ElasticPress/Elasticsearch index
<?php
add_filter(
'ep_prepare_meta_data',
function ( $prepared_meta ) {
foreach ( $prepared_meta as $key => $meta_val ) {
// Remove empty meta fields.
if ( empty( $key ) || empty( $meta_val ) || empty( $meta_val[0] ) ) {
unset( $prepared_meta[ $key ] );
continue;
}