Skip to content

Instantly share code, notes, and snippets.

Avatar

Drew Baker drewbaker

View GitHub Profile
@drewbaker
drewbaker / php
Created Jun 21, 2021
A PHP script as a starting point to convert old WP meta fields to ACF meta fields. Add this to theme's functions.php file.
View php
/*
* Use this script as a starting point to convert old WP meta fields to ACF meta fields.
* You should edit the script, and only run it once.
*/
function custom_convert_meta_to_acf()
{
// Get all pages/posts/cpts
$args = array(
'post_type' => 'any',
'posts_per_page' => -1,
@drewbaker
drewbaker / mock-api.gql
Last active Jan 4, 2021
This is used to generate the mock-api.json file used by fuxt
View mock-api.gql
query MockApi {
home: page(id: "/home", idType: URI) {
id
title
excerpt
content
uri
featuredImage {
node {
...MediaImage
@drewbaker
drewbaker / style.scss
Last active Dec 11, 2020
This makes sure portrait images used in wp-images don't become too tall
View style.scss
// This makes sure portrait images don't become too long
.wp-image.is-orientation-portrait {
max-height: 80vh;
/deep/ {
.sizer {
position: static;
}
.media {
object-fit: contain;
@drewbaker
drewbaker / custom-post-types.php
Created Nov 18, 2020
Create custom post types for different regions
View custom-post-types.php
<?php
/*
* Setup Custom Post Types
*/
function create_custom_posts() {
// Create a loop of all the post types we need
$types = array(
[
'name' => 'US Region',
@drewbaker
drewbaker / custom-taxonomies.php
Created Nov 18, 2020
Register custom "filter" taxonomy in WordPress
View custom-taxonomies.php
<?php
/*
* Add a custom taxonomy my for "Work Filter" certain post types
*/
function setup_work_filters() {
$labels = array(
'name' => 'Work filter',
'singular_name' => 'Work filter',
'search_items' => 'Search filters',
'popular_items' => 'Popular filters',
@drewbaker
drewbaker / api.php
Created Oct 29, 2020
WP JSON API SearchWP endpoint
View api.php
<?php
/*
* Register custom API endpoints
*/
function add_fuxt_api_routes()
{
// Sitemap
register_rest_route('fuxt', '/search', [
[
'methods' => 'GET',
@drewbaker
drewbaker / functions.php
Last active Jun 19, 2017
GeoIP functions for WordPress. Requires some external GeoIP files and .dat file from MaxMind.
View functions.php
/*
* Region Select Custom Post Type
*/
function cutandrun2016_post_type() {
// US editors
$us_post_labels = array(
'name' => _x('US Region', ''),
'singular_name' => _x('US Region', ''),
'add_new' => _x('Add New', 'editor'),
@drewbaker
drewbaker / functions.php
Created Jan 29, 2016
Blurring image using WordPress
View functions.php
/**
* Several functions relatting to blurring images on uploaded.
* @see https://codeable.io/community/how-to-watermark-wordpress-images-with-imagemagick/
*/
add_image_size( 'background-image-blurred', 1920, 1080, true );
function generate_blurred_image( $meta ) {
$time = substr( $meta['file'], 0, 7); // Extract the date in form "2015/04"
$upload_dir = wp_upload_dir( $time ); // Get the "proper" upload dir