Skip to content

Instantly share code, notes, and snippets.

@solepixel
solepixel / acf-sync-fields.php
Created December 30, 2015 10:20
Sync 2 relationship CPT fields in ACF that are connected. Example: Actors (Relationship Field) in a Movie (CPT), and Movies (Relationship field) an Actor (CPT) has been in.
<?php
function acf_sync_field( $sync_field, $value, $post_id, $field ){
// vars
$source_field = $field['name'];
$source_global_name = 'is_updating_' . $source_field;
$sync_global_name = 'is_updating_' . $sync_field;
// get this value early before anything is updated
@solepixel
solepixel / jquery.script.js
Last active June 15, 2022 02:24
Vertically and horizontally center Soliloquy slides while still keeping proportions. Emulating the "background-size: cover" with a standard slider. Slider configuration looks like this: Slider Dimensions: Full Width, Slider Position: Center, Use Adaptive Height: Yes, Crop Images in Slider: Yes
(function( $ ){
'use strict';
function auto_fit_soliloquy( parent_selector ){
// resize the slider container
var $soliloquy = $( parent_selector + ' .soliloquy-container'),
$all_items = $('.soliloquy-slider,.soliloquy-viewport,.soliloquy-item', $soliloquy ),
$container = $('.soliloquy-item', $soliloquy ),
window_height = $(window).height();
<?php
public function sync_active() {
if( get_transient( 'rets_data_sync_active' ) )
return;
set_transient( 'rets_data_sync_active', 'PAUSE', HOUR_IN_SECONDS * 4 );
global $rets_sync_db;
$rets_sync_db->add_filter( 'field_L_Status', 'Active' );
$listings = $rets_sync_db->get_listings();
@solepixel
solepixel / acf-set-field-name.php
Created June 8, 2016 04:46
Differentiate Settings Page fields when using the same field groups. Requires "menu_slug" prefixed with something common and identifiable, in this case the Post Type of the Archive as well as a common naming convention, in this example it uses "-archive-settings".
<?php
add_filter( 'acf/load_field', 'mytheme_set_field_name' );
function mytheme_set_field_name( $field ){
if( is_admin() ){
$screen = get_current_screen();
if( $screen->id == 'acf-field-group' )
return $field;
@solepixel
solepixel / gravityform-shortcode-ui.php
Last active November 1, 2017 14:33
Enable Shortcode UI (Shortcake) for Gravity Forms
<?php
/**
* Registers Shortcode UI for gravityforms shortcode
*
* @package theme
*/
if ( ! function_exists( '_theme_gravityform_shortcode_ui' ) ) {
/**
@solepixel
solepixel / activate-plugin.php
Created August 26, 2016 15:22
Originally design to activate Andrew Norcross's Airplane Mode plugin (https://github.com/norcross/airplane-mode), this little script will allow you to activate a plugin when the WordPress admin plugin screen cannot be loaded, for whatever reason.
<?php
/**
* This file will activate the Airplane Mode plugin if not already activated. This is helpful when you do not have internet connection and you're unable to reach the WP Admin Plugins page to activate the plugin.
*/
// get WP bootstrap
define('WP_USE_THEMES', false);
require(__DIR__ . '/wp/wp-blog-header.php');
Array
(
[from] => 0
[size] => 54
[sort] => Array
(
[0] => Array
(
[meta_value_num] => Array
(
@solepixel
solepixel / formatted-args.txt
Created September 7, 2016 04:30
ElasticPress arguments
Array
(
[from] => 0
[size] => 54
[sort] => Array
(
[0] => Array
(
[meta_value_num] => Array
(
@solepixel
solepixel / formatted-args.txt
Created September 7, 2016 20:37
Simpler Arguments for ElasticPress
Array
(
[from] => 0
[size] => 54
[sort] => Array
(
[0] => Array
(
[meta_value_num] => Array
(
@solepixel
solepixel / algolia-2.php
Last active October 27, 2020 04:35
Custom parameters for Algolia search in WordPress
<?php
add_filter( 'algolia_terms_index_settings', '__return_empty_array' );
add_filter( 'algolia_users_index_settings', '__return_empty_array' );
add_filter( 'algolia_posts_listing_index_settings', 'mytheme_algolia_listing_settings' );
function mytheme_algolia_listing_settings( $settings ){
$numeric_fields = array_keys( mytheme_algolia_faceted_fields( array( 'int', 'float' ) ) );
$string_fields = array_keys( mytheme_algolia_faceted_fields( 'string' ) );