Skip to content

Instantly share code, notes, and snippets.

View felipeelia's full-sized avatar

Felipe Elia felipeelia

View GitHub Profile
@felipeelia
felipeelia / woocommerce-orderby-featured-products.php
Last active August 3, 2023 13:47
Bring featured products first in a WP_Query
@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 / woocommerce-catalog-sort-snippet.php
Created July 5, 2017 12:22 — forked from mikejolley/gist:1622323
WooCommerce - Change default catalog sort order to stock status and date
/**
* This code should be added to functions.php of your theme
**/
function my_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_stock_status';
$args['orderby'] = array( 'meta_value' => 'ASC', 'date' => 'DESC' );
return $args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'my_woocommerce_catalog_orderby' );
@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": [
"",
"",
<?php
// Remove acentos e espaços dos arquivos no upload
function custom_sanitize_file_name ( $filename ) {
$filename = remove_accents( $filename );
$filename = strtolower( $filename );
$file_parts = pathinfo( $filename );
$new_filename = sanitize_title( $file_parts['filename'] );
if ( ! empty( $file_parts['extension'] ) ) {
@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 / elasticpress-related-posts-adjustments.php
Last active July 29, 2022 13:19
Tweaks for ElasticPress's Related Posts Features