Skip to content

Instantly share code, notes, and snippets.

View Hube2's full-sized avatar

John A. Huebner II Hube2

View GitHub Profile
@codytooker
codytooker / acf-sync-user-and-cpt-bidirectional-relationship.php
Created January 18, 2018 21:27
Modified version of the bidirectional relationship function to help facilitate users to cpt relationships
<?php
/*
* This code is modified from the original here
* https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-reciprocal-relationship.php
*
* Some comments may not be useful anymore since the modifications
*/
(function($) {
acf.add_action('ready', function( $el ){
//Identify the field you want to check against.
//Use a class to handle scenarios involving repeater / flexible content where multiple instances exist
var $field = $('.example input');
$field.on('change', function (evt) {
@mgibbs189
mgibbs189 / functions.php
Created March 17, 2016 16:26
Rename "Posts" to "Articles"
<?php
function fwp_rename_post( $params, $class ) {
if ( 'post_types' == $params['facet_name'] && 'post' == $params['facet_value'] ) {
$params['facet_display_value'] = 'Articles';
}
return $params;
}
add_filter( 'facetwp_index_row', 'fwp_rename_post', 10, 2 );
@senlin
senlin / language-independent-acf-theme-options-output.php
Last active June 26, 2024 08:58
How to get language independent ACF theme options on a WPML site
<?php
/**
* To get this to work, you need to tinker with the acf/settings/ filter and reset the default language
* so that the get_field() function returns the correct results even when not on the default language.
*
* You can add the filter before you call the get_field() function and then call it again with the current
* language to reset it again, so it will affect other pages.
*
* answer courtesy of James of ACF Support
*/
@webgurus
webgurus / acf-update-via-json-plus-sync.php
Created August 14, 2015 07:04
Automatically updates ACF field groups with JSON file modification
<?php
/**
* Function that will automatically update ACF field groups via JSON file update.
*
* @link http://www.advancedcustomfields.com/resources/synchronized-json/
*/
function jp_sync_acf_fields() {
// vars
$groups = acf_get_field_groups();
$sync = array();
@mcguffin
mcguffin / acf-get-field-key.php
Last active June 13, 2023 13:32
WordPress Advanced Custom Fields get field key from field name
<?php
/**
* Get field key for field name.
* Will return first matched acf field key for a give field name.
*
* ACF somehow requires a field key, where a sane developer would prefer a human readable field name.
* http://www.advancedcustomfields.com/resources/update_field/#field_key-vs%20field_name
*
* This function will return the field_key of a certain field.
@bedeabza
bedeabza / hexhsl.php
Created April 11, 2014 12:10
PHP Hex to HSL and HSL to Hex conversion
function hexToHsl($hex) {
$hex = array($hex[0].$hex[1], $hex[2].$hex[3], $hex[4].$hex[5]);
$rgb = array_map(function($part) {
return hexdec($part) / 255;
}, $hex);
$max = max($rgb);
$min = min($rgb);
$l = ($max + $min) / 2;
@hlashbrooke
hlashbrooke / function.php
Created July 12, 2013 11:13
WordPress: Add plugin settings link to plugins list table
<?php
function plugin_add_settings_link( $links ) {
$settings_link = '<a href="options-general.php?page=plugin_name">' . __( 'Settings' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
$plugin = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );
?>
@charleslouis
charleslouis / custom-search-acf-wordpress.php
Last active December 15, 2023 09:11
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@markjaquith
markjaquith / gist:2653957
Created May 10, 2012 15:36
WordPress Fragment Caching convenience wrapper
<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.