Skip to content

Instantly share code, notes, and snippets.

// CUSTOM FIELDS
add_filter( 'rwmb_meta_boxes', 'experience_cpt_meta_boxes2' );
function experience_cpt_meta_boxes2( $meta_boxes ) {
if( is_admin() )
return;
// CREATE TAXONOMY
$meta_boxes[] = array(
'title' => __('Crea Taxonomy','appgenova'),
@sododesign
sododesign / import-variation.php
Created November 14, 2018 10:54 — forked from galalaly/import-variation.php
Create WooCommerce variations with PHP
<?php
// In a class constructor
$this->size_tax = wc_attribute_taxonomy_name( 'Size' );
$this->color_tax = wc_attribute_taxonomy_name( 'Color' );
// Insert the main product first
// It will be used as a parent for other variations (think of it as a container)
$product_id = wp_insert_post( array(
@sododesign
sododesign / functions.php
Created October 21, 2018 12:19 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@sododesign
sododesign / wp-get-content
Created December 8, 2017 01:08 — forked from ihorvorotnov/wp-get-content
WordPress: get post content by ID
/**
* You often need to get the content or title from a specific post.
* Sometimes, using a custom loop is the better option, but when you only need
* to get information from a specific post, there’s a better option
*/
echo get_post_field('post_content', $post_id);
@sododesign
sododesign / load.php
Created November 24, 2017 16:54 — forked from yratof/load.php
ACF Load layouts into flex field
<?php
add_filter( 'acf/load_field/name=flex_layout', __CLASS__ . '::craft_content_layouts' );
static function craft_content_layouts( $field ) {
// Remove the layouts
// that are named in this list
$remove_list = [
'paragraph',
'banner',
@sododesign
sododesign / auto-activate-plugins.php
Created May 2, 2017 09:16
WordPress Multisite: Automatically enable plugins in new blogs
<?php
// There are three options (that I know of) for automatically enabling a plugin
// in new sites.
// 1. Move the plugin from wp-content/plugins/ to wp-content/mu-plugins/ (MU =
// Must Use). But then it cannot be deactivated for any site.
// 2. Click "Network Activate" instead of "Activate" to enable it for all sites.
// I didn't want to use this though because I didn't want to affect existing
<?php
/*=========================================
Custom Submit Box
==========================================*/
/**
* Loop throught custom post types and
* replace default submit box
*
* @since 1.0
*
@sododesign
sododesign / excerpt.php
Last active February 10, 2016 18:17
WORDPRESS GET EXCERPT
<?php
/*-----------------------------------------------------------------------------------*/
// EXCERPT SIZE
/*-----------------------------------------------------------------------------------*/
function get_excerpt() {
$output = substr(get_the_excerpt(), 0,85);
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = $output;
@sododesign
sododesign / WordPress Custom Global Variables.md
Created January 9, 2016 18:00 — forked from aahan/WordPress Custom Global Variables.md
Creating and using custom global variables in wordpress.

First create global variables (in functions.php or as a mu-plugin):

<?php

/*
 * CUSTOM GLOBAL VARIABLES
 */
function wtnerd_global_vars() {
@sododesign
sododesign / translate_wpml_media_acf.php
Created January 9, 2016 15:38
Translate ACF Media with WPML
<?php
/**
* Make Media attachments translatable with WPML
*
* Filter ACF images and galleries to switch attachment ids with their
* corresponding WPML translation.
*/
add_filter( 'acf/load_value/type=gallery', 'my_acf_load_translated_attachment', 10, 3 );
add_filter( 'acf/load_value/type=image', 'my_acf_load_translated_attachment', 10, 3 );