Skip to content

Instantly share code, notes, and snippets.

View alexwcoleman's full-sized avatar

Alex Coleman alexwcoleman

View GitHub Profile
@alexwcoleman
alexwcoleman / functions.php
Created October 25, 2019 04:51
CMB2 Image Repeater to ACF Pro Repeater
// PLEASE NOTE!
// I set my ACF Image Repeater to return only the image ID...
// So this may not work if you have it set to return an Object or...?
// I found this helpful: https://support.advancedcustomfields.com/forums/topic/repeater-update_field/
add_action( 'init', 'cmb2_to_acf' );
function cmb2_to_acf() {
// You can use offset if needed.
$args = array(
@alexwcoleman
alexwcoleman / functions.php
Created October 17, 2019 04:46
CMB2 to ACF Repeater
// make sure to comment out add_action when you're done, or working on the data
add_action( 'init', 'cmb2_to_acf' );
function cmb2_to_acf() {
// You can use offset if needed.
$args = array(
'post_type' => 'some_post_type',
'numberposts' => 400, // whatever number.
// 'offset' => 800,
);
@alexwcoleman
alexwcoleman / functions.php
Created October 8, 2019 21:19
Moving WooCommerce Images to ACF Repeater subfields
add_action( 'init', 'test_update_products' );
function test_update_products() {
// You can use offset if needed.
$args = array(
'post_type' => 'my_awesome_cpt',
'numberposts' => 300,
//'offset' => 1000,
);
@alexwcoleman
alexwcoleman / functions.php
Created November 15, 2018 06:52
WordPress Cleanup
<?php
// ALL OF THIS IS FROM: https://www.linkedin.com/pulse/wp-speed-up-from-ground-alex-knopp
// Post Revisions
// WordPress will simply store every single post revision you create. If your a developer like me then my clients websites change a lot and these post revisions build up. Add the following to your wp-config.php file to stipulate the number of post revisions saved at any one time.
//Define the number of post revisions to be saved
define( 'WP_POST_REVISIONS', 3 );
// WordPress Bloat
@alexwcoleman
alexwcoleman / functions.php
Created October 4, 2018 22:27
Adding Custom Endpoints to The Events Calendar
// this filter adds the custom field values to the json output for The Events Calendar
// https://theeventscalendar.com/support/forums/topic/custom-field-output-for-json-feed/
add_filter( 'tribe_rest_event_data', 'omfg_add_event_customfields' );
function omfg_add_event_customfields($data) {
$event_id = $data['id'];
$some_data = 'some data';
$data = array_merge( $data,
// This is for a single value
(function($) {
let pages = [
'Home',
'About',
'Contact'
// whatever....
];
function addPages(pageArray){
// Create a page with the WordPress REST API
@alexwcoleman
alexwcoleman / spacing.scss
Created July 24, 2018 18:23
Create Spacing Classes in SASS
$spacing-values: (
1,
2,
3,
4,
5,
);
@each $val in $spacing-values {
// REMS
@alexwcoleman
alexwcoleman / remote-media-loader.php
Last active April 10, 2018 20:46
Remote Media Loader: WordPress
<?php
/**
* Loads media from a remote site when on a local dev environment.
* Eliminates the need to download the uploads directory from the remote site for testing purposes.
* Just make sure to update the obvious URLs below 🤔👏🎉
* Also, throw this in your mu-plugins folder, or create a plugin for yourself.
*/
if ( 'yourbigfatwebsite.local' === $_SERVER['HTTP_HOST'] ):
add_filter( 'upload_dir', function ( $uploads ) {
$uploads['baseurl'] = 'http://yourbigfatwebsite.com/wp-content/uploads';
@alexwcoleman
alexwcoleman / logo-in-menu.php
Created March 9, 2018 15:48
Add A Logo/Site Title/Whatever to WordPress Navigation
class logo_in_nav_Walker extends Walker_Nav_Menu {
// from https://wordpress.stackexchange.com/questions/256868/walker-nav-menu-put-custom-code-between-a-particular-li
public $site_title;
public $site_url;
function __construct() {
$this->menu_location = 'primary';
$this->site_title = get_bloginfo( 'name' );
$this->site_url = get_bloginfo( 'url' );
}
@alexwcoleman
alexwcoleman / functions.php
Created September 19, 2017 18:38
Add description to Featured Image Metabox in WordPress
// HTML is whatever you like
function awc_post_thumbnail_add_description( $content, $post_id ){
$post = get_post( $post_id );
$post_type = $post->post_type;
if ( $post_type = 'post') {
$content .= "<div style='background-color: #eee;padding: 1rem;'>
<h3><label for=\"html\"><strong>Best size: <br>900px wide by 600px tall</strong></label></h3>
</div>";
return $content;
return $post_id;