Skip to content

Instantly share code, notes, and snippets.

View solid-pixel's full-sized avatar

Alessandro Benassi solid-pixel

View GitHub Profile
@solid-pixel
solid-pixel / page.php
Created January 6, 2017 14:32
Grab Custom Posts from specific Taxonomy
<ul>
<?php
$query = new WP_Query( array(
'post_type' => 'course', //post type slug
'tax_query' => array(
array(
'taxonomy' => 'course_type', //taxonomy slug
'field' => 'slug',
'terms' => 'post-graduate') //term slug
)) );
@solid-pixel
solid-pixel / page.php
Created January 6, 2017 14:34
Register Taxonomy exclusive to a specific custom post type
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'course_type', //taxonomy slug
'course', // custom post type slug
array(
'hierarchical' => true, //shows as category, set false to show as tags
'label' => 'Course Type', //taxonomy label
'query_var' => true,
'rewrite' => true
@solid-pixel
solid-pixel / functions.php
Created January 19, 2017 16:03
Create taxonomy term with same name as Post Title
// Create taxonomy term with same name as Post Title
function create_course_name($post_ID) {
global $wpdb;
$cat = get_the_title($post_ID); // grabs the post title
wp_set_object_terms($post_ID, $cat, 'course_name'); //course_name is the taxonomy slug
}
add_action('save_post', 'create_course_name'); // This creates the term on Save
@solid-pixel
solid-pixel / functions.php
Created January 20, 2017 18:26
Assign Taxonomy Term with same name as Post Object's assigned title
<?php
// Assign a taxonomy term with the same name as the Course assigned to the Tutor
function create_tutors_course($post_ID) {
global $wpdb;
$postObjectID = get_field('tutor_course', false, false); //grab the assigned Course's post ID
if($postObjectID) {
$catName = get_the_title($postObjectID); //grab the title of the Course
wp_set_object_terms($post_ID, $catName, 'course_name'); //course_name is the taxonomy slug
@solid-pixel
solid-pixel / functions.php
Created March 1, 2017 10:48
Add Custom Items to Specific WordPress Menus
/*------------------------------------*\
ADD CUSTOM ITEM TO MENU (ACF)
\*------------------------------------*/
add_filter('wp_nav_menu_items','custom_menu_item', 10, 2);
function custom_menu_item( $items, $args ) {
if( $args->menu->slug == 'menu-1') {
$content = get_field('brochure-link', 'option');
$items .= '<li>' . $content . '</li>';
@solid-pixel
solid-pixel / page.php
Created March 2, 2017 16:45
Set ACF Object Image as Background
<?php
$image = get_field('image_field_slug'); // the image field slug - set the field Return Value to 'Array'
$size = 'large'; // the image size
$thumb = $image['sizes'][ $size ]; //get the URL
echo '<div class="div-30" style="background:url(' . $thumb . ')"></div>';
?>
@solid-pixel
solid-pixel / functions.php
Created March 3, 2017 19:08
Replace WP Gallery with The Grid plugin gallery
/*------------------------------------*\
REPLACE WP GALLERY WITH THE_GRID PLUGIN
\*------------------------------------*/
$GLOBALS['the_grid_gallery'] = 'Gallery'; // add your grid name here
// remove the native gallery shortcode
remove_shortcode('gallery');
// redeclare the gallery shortcode
add_shortcode('gallery', 'the_grid_gallery_shortcode');
function the_grid_gallery_shortcode($ids) {
@solid-pixel
solid-pixel / plugin-name.php
Last active March 15, 2017 17:08
Use a plugin to load JS files
<?php
/**
* Plugin Name: Plugin Name
* Plugin URI: http://solidpixel.com
* Description: Description
* Version: 1.0.0
* Author: Pelly
* Author URI: http://solidpixel.com
* License: GPL2
*/
@solid-pixel
solid-pixel / scripts.js
Created March 17, 2017 15:35
Target classes with Vivus JS
jQuery(function () {
// Define your callback
var myCallback = function () {
// action to execute after SVG animation is complete - optional
};
// Get your HTMLCollection of SVG to animate
var myElements = jQuery(".animate svg");
@solid-pixel
solid-pixel / functions.php
Created March 20, 2017 12:01
Prefill ACF field with Post Title
function my_acf_load_value( $value, $post_id, $field ) { $value = get_the_title(); return $value; } add_filter('acf/load_value/name=FIELD_NAME', 'my_acf_load_value', 10, 3);