Skip to content

Instantly share code, notes, and snippets.

@wplit
wplit / code-block.php
Last active September 23, 2021 01:56
open accordion header when linked to with button. updated - add to code block
jQuery(document).ready(function($) {
let buttonSelector = '.research-card-image-overlay';
let delay = 500;
$(buttonSelector).on('click', function() {
if ($(this).attr('href')) {
let hash = $(this).attr('href').split('#')[1];
if (hash) {
@MogulChris
MogulChris / theme-elasticsearch.php
Created November 23, 2020 04:00
ElasticPress modifications
//Search fields indexed by post type. Yes, I should do this in a tidier way.
global $search_index_fields;
$search_index_fields = array(
'still_image' => array('people','business','location','format_original','author','notes'),
'audio' => array('people','business','transcript','format_original','author','additional'),
'video' => array('people','business','format_original','transcript','author','additional'),
'person' => array('name','known_as','maiden_name','military_identification','birthplace','parents','partner','children','deathplace','biography'),
'text' => array('people','business','location','format_original','author','notes','publisher','transcript')
);
@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;
}
@yankiara
yankiara / oxygen-repeater-dynamic-query.php
Last active September 6, 2023 19:25
Use dynamic queries with Oxygen's repeater
/* I'll put here different examples of dynamic query for Oxygen repeater :
* - Use one of the following repeater_dynamic_query definitions
* in code block just BEFORE the repeater
* - Set the repeater custom query settings : post type, number of posts, order...
* - Add the remove_action in a code block AFTER the repeater
*/
/****************************************************************************************************
* Display related posts for any CPT with taxonomy:
@wplit
wplit / tab-element.js
Last active December 14, 2022 09:57
Allow hash links to open tabs in Oxygen (read comments for instructions)
var hash = window.location.hash.substr(1);
if (hash == '%%ELEMENT_ID%%') {
setTimeout(function(){
jQuery([document.documentElement, document.body]).animate({
scrollTop: jQuery('#' + '%%ELEMENT_ID%%').offset().top - 100
}, 1000);
jQuery('#' + '%%ELEMENT_ID%%').trigger('click');
@mgibbs189
mgibbs189 / functions.php
Last active June 3, 2021 03:17
FacetWP - disable ElasticPress during querying
<?php
function disable_elasticpress_integration( $query_args ) {
add_filter( 'ep_skip_query_integration', '__return_true' );
return $query_args;
}
add_filter( 'facetwp_query_args', 'disable_elasticpress_integration' );
@denji
denji / nginx-tuning.md
Last active May 3, 2024 03:57
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@kloon
kloon / functions.php
Last active November 26, 2020 02:21
WooCommerce set tax exemption based on user role
<?php
add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesaler') || current_user_can('distributor') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}