Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@willybahuaud
willybahuaud / default-term.php
Last active October 17, 2022 16:45
Set a default term for custom taxonomy and custom post type
<?php
add_action( 'wp_insert_post', 'willy_set_default_term', 10, 3 );
function willy_set_default_term( $post_id, $post, $update ) {
if ( 'cpt' == $post->post_type ) { // replace `cpt` with your custom post type slug
/**
* Replace `taxo` by the taxonomy slug you want to control/set
* … and replace `default-term` by the default term slug (or name)
* (or you can use a `get_option( 'my-default-term', 'default term' )` option instead, which is much better)
*/
if ( empty( wp_get_post_terms( $post_id, 'taxo' ) ) ) {
@Rahe
Rahe / class-terms-fields.php
Last active December 26, 2020 22:31
Load all ACF terms Fields into the term object
<?php
/**
* Class ACF_Terms_Fields
* @version 1.1.0
*
* Fill all the taxonomy terms with ACF metas
*/
class ACF_Terms_Fields {
/**
@Rarst
Rarst / WordPress.xml
Last active September 5, 2024 01:49
WordPress Live Templates for PhpStorm
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="WordPress">
<template name="aa" value="add_action( '$hook$', '$callback$' );&#10;$END$" description="add_action" toReformat="false" toShortenFQNames="true">
<variable name="hook" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="callback" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
@eltonmesquita
eltonmesquita / onViewport.js
Last active November 1, 2020 09:32
A simple jQuery function that adds a class when the target(s) is in the viewport
function onViewport(el, elClass, offset, callback) {
/*** Based on http://ejohn.org/blog/learning-from-twitter/ ***/
var didScroll = false;
var this_top;
var height;
var top;
if(!offset) { var offset = 0; }
$(window).scroll(function() {
add_action( 'wp_footer', 'infinite_load' );
function infinite_load() {
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
?>
<script>
jQuery(document).ready(function($){
if( window.history && history.pushState ) {
var $page = <?php echo $paged; ?>;
@Ciantic
Ciantic / gist:8a09107fcd9bed8bede0
Created June 24, 2014 16:41
WordPress select and checkboxes metabox callback
<?php
/**
* Show taxonomy selection in WordPress admin as single <select> box or checkboxes
*
* @author Jari Pennanen / https://github.com/ciantic
* @license Public Domain
**/
// Usage example:
register_taxonomy("my_taxonomy", array("post"), array(
@herewithme
herewithme / bea-acf-helpers.php
Created December 3, 2013 16:20
Small class helper for get ACF fields for a specific post type
<?php
class BEA_ACF_Helpers {
// Fields to not add to the available fields of acf
private static $unauth_fields = array(
'repeater',
'relationship',
'flexible_content'
);
/**