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 / trim-words.php
Created July 24, 2024 18:15 — forked from barbwiredmedia/trim-words.php
Wordpress trim words shorten post meta / custom field. ACF wp_trim_words create an excerpt. http://codex.wordpress.org/Function_Reference/wp_trim_words
<?php
$content = get_post_meta($post->ID, your_custom_field_meta, true);
$trimmed_content = wp_trim_words($content, 15, '... <a href="' . get_permalink() . '">Read More</a>');
echo $trimmed_content;
?>
<?php echo get_option('home'); ?> <!-- get the home URL -->
<?php bloginfo('description'); ?> <!-- display the blog description -->
<?php bloginfo('name'); ?> <!-- display the blog name -->
<?php bloginfo('template_directory') ?> <!-- get the home URL for template's directory -->
<?php echo get_template_directory_uri(); ?>
<?php wp_list_pages('sort_order=desc&title_li='); ?> <!-- display the page list in descending order withour title -->
<?php wp_list_pages('sort_order=desc&depth=1&title_li='); ?> <!-- display the page list in descending order with "current_page_item" class
<?php wp_list_bookmarks(); ?> <!-- display the list of blogrolls -->
<?php echo date('Y'); ?>
@dgoze
dgoze / readonly_and_disabled_to_text_acf.php
Created July 24, 2024 18:14 — forked from vovadocent/readonly_and_disabled_to_text_acf.php
Readonly and disabled to ACF text field
<?php
add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
function add_readonly_and_disabled_to_text_field($field) {
acf_render_field_setting( $field, array(
'label' => __('Read Only?','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'readonly',
'choices' => array(
1 => __("Yes",'acf'),
@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 ) ) {