Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / get-acf-sub-field-key-by-field-name-function.php
Last active October 1, 2019 22:27
A function for determining an ACF field's sub field key based on a field name. For more info see https://philkurth.com.au/tips/get-an-acf-sub-field-key-by-field-name/
<?php
/**
* Locates an ACF sub-field by field name and returns the sub-field's key.
*
* This is particularly useful if you need to construct a data array for programmatic field
* update where a complex field is in use (e.g; repeater, group, flexi).
*
* @param string $sub_field_name The sub field name we need a key for.
* @param array $field The ACF field array.
.m-0-first-last > :first-child {
margin-top: 0;
}
.m-0-first-last > :last-child {
margin-bottom: 0;
}
<?php
add_action( 'wp_enqueue_scripts', function () {
$uri = get_stylesheet_directory_uri();
$dir = get_stylesheet_directory();
$script_last_updated_at = filemtime( "$dir/scripts/my-script.js" );
$style_last_updated_at = filemtime( "$dir/styles/my-style.css" );
@mishterk
mishterk / 0-readme.md
Last active July 1, 2020 11:21
A basic example for querying data from custom tables created using ACF Custom Database Tables. For more info see https://hookturn.io/2019/09/how-to-use-acf-custom-database-tables-data-with-wp_query-objects/

How to use your custom table data with WP_Object queries

This example illustrates how to query an array of post IDs from a custom DB table then use the array in a WP_Query.

This can be much faster than using meta queries on a WP_Query object, particularly if you are matching multiple fields.

@mishterk
mishterk / ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass.php
Last active September 11, 2019 02:43
A hotfixed solution for bypassing custom database tables when using ACF's get_field() function. This will ONLY work with 1.0.x versions of the plugin. Version 1.1 will include built-in support for this capability.
<?php
use ACFCustomDatabaseTables\Intercept\ACFGetFieldIntercept;
use ACFCustomDatabaseTables\Vendor\Pimple\Container;
/**
* Class ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass
*
* This provides a 'hotfixed' approach for disabling custom database table intercept when using ACF's get_field()
* function. This will only work with version 1.0.x versions of the plugin as a built-in tool will be available in
@mishterk
mishterk / register-basic-wysiwyg-toolbar-for-acf.php
Last active April 19, 2024 02:08
Register custom WYSIWYG field toolbar options with Advanced Custom Fields for WordPress (ACF).
<?php
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
$toolbars['Bare'] = [];
$toolbars['Bare'][1] = [ 'forecolor', 'link', 'strikethrough', 'bold', 'italic' ];
return $toolbars;
} );
@mishterk
mishterk / register-acf-json-load-directory.php
Last active June 3, 2022 19:32
How to load ACF JSON files from additional directories. See https://www.awesomeacf.com/snippets/load-acf-json-files-from-multiple-locations/ for more details.
<?php
add_filter( 'acf/settings/load_json', function ( $paths ) {
$paths[] = get_template_directory() . '/some/custom/dir';
return $paths;
} );
@mishterk
mishterk / register-acf-options-page.php
Last active June 3, 2022 20:33
How to register options pages in Advanced Custom Fields for WordPress (ACF). See https://www.awesomeacf.com/snippets/register-options-page/ for more details.
<?php
// register a top-level options page
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page( [
'page_title' => 'My Options Page',
'menu_title' => 'My Options Page',
'menu_slug' => 'my-options-page',
'capability' => 'edit_posts',
'parent_slug' => '',
@mishterk
mishterk / bypass-elementors-maintenance-mode.php
Last active April 4, 2024 13:29
Using this snippet, you can bypass Elementor's maintenance mode by adding ?bypass_maintenance=1 to the query string
<?php
add_filter( 'pre_option_elementor_maintenance_mode_mode', function ( $option ) {
$parameter = 'bypass_maintenance'; // change this to whatever you like
if ( isset( $_GET['bypass_maintenance'] ) and $_GET['bypass_maintenance'] ) {
return 0; // needs to be falsy but not FALSE
}
@mishterk
mishterk / custom-wordpress-menu-items-template.php
Last active December 25, 2024 16:19
How to render WordPress menu items without a custom walker
<?php $menu_location = 'some_menu_location'; ?>
<?php if ( has_nav_menu( $menu_location ) ): ?>
<?php $menu_items = wp_get_nav_menu_items( wp_get_nav_menu_name( $menu_location ) ); ?>
<?php foreach ( $menu_items as $menu_item ): ?>
<a href="<?= esc_url( $menu_item->url ) ?>"
target="<?= esc_attr( $menu_item->target ?: '_self' ) ?>"