Skip to content

Instantly share code, notes, and snippets.

Avatar

Thierry Pigot thierrypigot

View GitHub Profile
@willybahuaud
willybahuaud / default-term.php
Last active Oct 17, 2022
Set a default term for custom taxonomy and custom post type
View default-term.php
<?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 Dec 26, 2020
Load all ACF terms Fields into the term object
View class-terms-fields.php
<?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 Aug 5, 2021
WordPress Live Templates for PhpStorm
View WordPress.xml
<?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 Nov 1, 2020
A simple jQuery function that adds a class when the target(s) is in the viewport
View onViewport.js
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() {
View gist:1207324668fc59255dee
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 Jun 24, 2014
WordPress select and checkboxes metabox callback
View gist:8a09107fcd9bed8bede0
<?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 Dec 3, 2013
Small class helper for get ACF fields for a specific post type
View bea-acf-helpers.php
<?php
class BEA_ACF_Helpers {
// Fields to not add to the available fields of acf
private static $unauth_fields = array(
'repeater',
'relationship',
'flexible_content'
);
/**