View use-acfs-load-field-filter-with-advanced-forms.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'acf/load_field/key=TARGET_FIELD_KEY_HERE', 'afp_test_acf_load_field_filter' ); | |
function afp_test_acf_load_field_filter( $field ) { | |
$field['choices'] = []; | |
// Using get_posts() instead of WP_Query prevents query loop issues and global var overrides that break | |
// functionality on the advanced forms edit screen and potentially other contexts. | |
$posts = get_posts( [ |
View acf-export-group_63799935b6476.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"key": "group_63799935b6476", | |
"title": "Calculated Fields", | |
"fields": [ | |
{ | |
"key": "field_637999367d114", | |
"label": "Number 1", | |
"name": "number_1", | |
"aria-label": "", |
View load-images-from-production.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Load Images From Production (for staging/dev) | |
* Description: Hooks into WP's media URL generation and replaces the domain with the production domain. | |
* Author: Phil Kurth | |
* Author URI: https://hookturn.io | |
*/ | |
// If this file is called directly, abort. | |
defined( 'WPINC' ) or die(); |
View replace-images-with-kittens.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_get_attachment_image_src', function ( $image ) { | |
$image[0] = "https://placekitten.com/$image[1]/$image[2]"; | |
return $image; | |
}, 10 ); |
View register-custom-admin-columns.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_type = 'my_post_type'; | |
// Register the columns. | |
add_filter( "manage_{$post_type}_posts_columns", function ( $defaults ) { | |
$defaults['custom-one'] = 'Custom One'; | |
$defaults['custom-two'] = 'Custom Two'; |
View how-to-add-where-clause-to-wp-query-1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Hook the filter before calling the query. Note that we are using an anonymous | |
// function here and saving a reference to the `$fn` variable for use further down. | |
add_filter( 'posts_where', $fn = function ( $where, WP_Query $wp_query ){ | |
global $wpdb; | |
// Add a clause that ensures we only get posts with an ID greater than 200. | |
$where .= " AND {$wpdb->posts}.ID > 200"; | |
View use-acf-field-as-fallback-for-excerpt.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_the_excerpt', function ( $excerpt, $post ) { | |
if ( ! empty( $excerpt ) ) { | |
return $excerpt; | |
} | |
// On a specific post type, use an ACF field value as the excerpt. | |
if ( $post->post_type === 'my_custom_post_type' ) { | |
$excerpt = get_field( 'product_description', $post->ID ); |
View woocommerce-trim-zeros-from-price.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Need to trim zeros from a price on the fly? | |
$price = 49.00; // Can be numeric or a string. | |
$price = wc_trim_zeros( $price ); // === '49' | |
View disable-deprecation-notice-logging.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Disable deprecation notices so we can get a better idea of what's going on in our log. | |
// These hooks are all in wp-includes/functions.php. | |
// Note that these hooks don't stop WooCommerce from logging deprecation notices on AJAX | |
// or REST API calls as it makes its own calls to `error_log()` from within | |
// woocommerce/includes/wc-deprecated-functions.php. | |
add_filter( 'deprecated_constructor_trigger_error', '__return_false' ); | |
add_filter( 'deprecated_function_trigger_error', '__return_false' ); | |
add_filter( 'deprecated_file_trigger_error', '__return_false' ); |
View pluralise-string-based-on-variable-with-sprintf-and-acf.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use an ACF field value to pull the number from the database. | |
$number_of_items = (int) get_field('my_numerical_field', $post_id ); | |
$string = sprintf( | |
_n( | |
'%d item in stock', | |
'%d items in stock', | |
$number_of_items |
NewerOlder