Skip to content

Instantly share code, notes, and snippets.

@jrgd
jrgd / gist:3be90fa57c9be0e1fa95e30b1dade693
Last active March 27, 2018 20:38
Set Term (custom taxonomy) on post programmatically
$term = wp_create_term($term_name, 'taxonomy'); // will return existing term if exists already
wp_set_post_terms($post_id, $term_name, 'taxonomy');
@jrgd
jrgd / gist:d99929e88ba059ea0cb7efad575cf3e4
Last active March 27, 2018 20:35 — forked from hissy/gist:7352933
[WordPress] Add file to media library programmatically
function upload_image($file_name, $parent_post_id) {
$file = './img/'.$file_name;
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
@jrgd
jrgd / gist:984a1e3914fa37a083ec184722e2d684
Last active March 27, 2018 20:39
Insert ACF Post Meta
// Simple ACF Field insertion based on explanation here:
// https://support.advancedcustomfields.com/forums/topic/acf-repeater-filed-in-add_post_meta/
// and the awesome Get Field Key https://gist.github.com/mcguffin/81509c36a4a28d9c682e
function insert_acf_post_meta($key, $value_to_insert, $id) {
$field_name = $key;
$field_name__ = "_".$field_name;
$field_key = acf_get_field_key( $field_name, $id );
add_post_meta($id, $field_name, $value_to_insert, true);
@jrgd
jrgd / Laravel-Blade-Template-Cheatsheet
Last active November 17, 2017 10:11 — forked from CiprianSpiridon/Laravel-Blade-Template-Cheatsheet
Laravel Blade Template Cheatsheet
{!! $html !!} - Outputs HTML
{{ $var }} - Echo content
{{ $var or 'default' }} - Echo content with a default value
{{{ $var }}} - Echo escaped content
{{-- Comment --}} - A Blade comment
@extends('layout') - Extends a template with a layout
@if(condition) - Starts an if block
@else - Starts an else block
@elseif(condition) - Start a elseif block
@endif - Ends a if block