Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / acf-taxonomy-depth.php
Created July 24, 2024 18:14 — forked from WazzaJB/acf-taxonomy-depth.php
Advanced Custom Fields Taxonomy Depth Location Rule
<?php
//ADD RULE TO SECTION
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
$choices['Other']['taxonomy_depth'] = 'Taxonomy Depth';
return $choices;
}
//MATCHING OPERATORS
@dgoze
dgoze / acf-post-type-supports.php
Created July 24, 2024 18:14 — forked from QWp6t/acf-post-type-supports.php
Adds ACF Field Group location rule for Post Type Support.
<?php
/**
* Plugin Name: Field Group Location: Post Type Supports
* Plugin URI: http://qwp6t.me/acf-post-type-supports
* Description: Adds ACF Field Group location rule for Post Type Support. NOTE: You must first declare the supported feature in your theme.
* Version: 1.0.0
* Author: QWp6t
* Author URI: http://qwp6t.me
* License: MIT License
*/
@dgoze
dgoze / ACFToArray.php
Created July 24, 2024 18:13 — forked from teolaz/ACFToArray.php
This class is an helpful method to add a caching layer to Advanced Custom Fields. This works adding a new row on database with the entire ACF data serialized for that saved post or option page, and then WITH A SINGLE QUERY done you can have all data back and ready to use.
<?php
/**
* Created by PhpStorm.
* User: Matteo
* Date: 04/07/2018
* Time: 12:52
*/
/**
* Class ACFToArray
@dgoze
dgoze / advanced-custom-fields-post-title.php
Created July 24, 2024 18:13 — forked from philhoyt/advanced-custom-fields-post-title.php
Using Advanced Custom Fields to create your Post Title
<?php
/** Create Title and Slug */
function acf_title( $value, $post_id, $field ) {
if ( get_post_type( $post_id ) === 'staff' ) {
$new_title = get_field( 'first_name', $post_id ) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
wp_update_post(
array(
@dgoze
dgoze / acf-sync-fields.php
Created July 24, 2024 18:13 — forked from solepixel/acf-sync-fields.php
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
@dgoze
dgoze / _custom-wpadmin.php
Created July 24, 2024 18:13 — forked from paulburgess/_custom-wpadmin.php
Customised Wordpess admin area functions - include in your functions.php file
<?php
// =================================================================
// ====== Custom admin + menus
// =================================================================
/* Theme support for menus */
add_theme_support( 'menus' );
// Remove width and height attributes from images via WYSIWYG/admin
<?php
/**
* Set excerpt from ACF field
*/
add_action('acf/save_post', function($post_id) {
$post_excerpt = get_field( 'short_description', $post_id );
if ( ( !empty( $post_id ) ) AND ( $post_excerpt ) ) {
@dgoze
dgoze / wordpress_search_in_custom_fields.php
Created July 24, 2024 18:12 — forked from gradosevic/wordpress_search_in_custom_fields.php
WordPress: Search in ACF fields, functions.php
<?php
///////////////////////////////////
/// SUPPORT FOR SEARCHING IN ACF
///////////////////////////////////
/* Join posts and post-meta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;
@dgoze
dgoze / functions.php
Created July 24, 2024 18:11 — forked from paulburgess/functions.php
Useful functions for Wordpress
<?php
//require( get_template_directory() . '/_/inc/_custom-post-types.php' );
// Load jQuery
if ( !function_exists( 'core_mods' ) ) {
function core_mods() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
@dgoze
dgoze / ACF: Random image from Gallery
Created July 24, 2024 18:11 — forked from tjhole/ACF: Random image from Gallery
ACF: Random image from Gallery