Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
ChrisLTD / functions.php
Created May 8, 2014 16:22
Fix so you can preview ACF field changes in Wordpress admin
<?php
/*
Debug preview with custom fields
Taken from: http://support.advancedcustomfields.com/forums/topic/preview-solution/
See also: http://support.advancedcustomfields.com/forums/topic/2nd-every-other-post-preview-throws-notice/
*/
add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
$fields["debug_preview"] = "debug_preview";
return $fields;
@ChrisLTD
ChrisLTD / gist:9240291
Last active October 31, 2024 00:21
Wordpress Tag Shortcode
<?php
/*
* Tag Shortcode
* Usage: [tag type="span" class="myClass" id="firstSpan"]Lorem ipsum dolor sit amet[/tag]
*/
function tag_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'class' => 'shortcode_class',
'id' => '',
'type' => 'div',
@ChrisLTD
ChrisLTD / gist:957014
Created May 5, 2011 13:28
Django Nested Regroup Example (Group by category foreign key, then month of start date)
#views.py
def events_index(request, year):
selected_year = Year.objects.get(title=year)
events_list = Event.objects.filter(year = selected_year.id).order_by('category','start_date')
return render_to_response('events_list.html', {"events_list": events_list})
#events_list.html
{% regroup events_list by category.title as events_list_by_category %}
@ChrisLTD
ChrisLTD / gist:5877800
Created June 27, 2013 16:11
Loop through all custom taxonomy terms for a post type
<?php
$post_type = 'post';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ){
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( $taxonomy );
foreach( $terms as $term ){
echo $term->name;
}
@ChrisLTD
ChrisLTD / google-maps-example.html
Created July 14, 2013 00:27
Google Maps API V3 map w/ multiple markers, info boxes and auto center
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"></script>
</head>
<body>
<div id="map" style="width: 500px; height: 400px;"></div>
@ChrisLTD
ChrisLTD / waitForGraphQL.ts
Created April 18, 2023 00:45
Helper you can use to wait for specific graphql queries to finish in Playwright
import { Page } from '@playwright/test';
export async function waitForGraphQL(
page: Page,
operationName: string
): Promise<void> {
await page.waitForResponse(async (response) => {
if (response.url().endsWith('/graphql')) {
const responseText = await response.text();
const responseData = JSON.parse(responseText);
/*
Launch Darkly Context Provider using their JavaScript Client SDK
This component is used to provide the feature flags context to the rest of the app.
This is how you can use feature flags in your components:
1) Add your flag to the `Flags` constant in this file if it's not already there:
myFlag: { slug: 'my-flag', defaultValue: false },
@ChrisLTD
ChrisLTD / recalculate-acf-locations.php
Last active November 22, 2021 15:40 — forked from RadGH/recalculate-acf-locations.php
Update ACF location fields
<?php
// Update google map latitude/longitude after importing, using address
//
// https://support.advancedcustomfields.com/forums/topic/how-to-update-google-map-latitudelongitude-after-importing-using-address/
// https://gist.githubusercontent.com/RadGH/428bd8133c34dae60c0c/raw/fbfb0536abd1afc0fad1d2ed2b51c69304406c78/recalculate-acf-locations.php
//
// INSTRUCTIONS
// 1. Grab the file from this Gist and upload it to your theme.
// 2. Configure the options in the variable $ld_recalc. You MUST set the post type, and set the different field keys (see Finding the Field Key).
// 3. Call the file at the top of your functions.php script using include "recalculate-acf-locations.php";
(function keepVideoFromSkipping() {
// modified from https://stackoverflow.com/a/39754847
function modifyBehavior(video) {
var timeTracking = {
watchedTime: 0,
currentTime: 0
};
var lastUpdated = 'currentTime';
@ChrisLTD
ChrisLTD / docker-compose.yml
Last active November 14, 2020 00:37
Docker Compose for WordPress with Data Persistence
# Docker Compose for WordPress with Data Persistence
#
# Resources
# https://medium.com/@tatemz/local-wordpress-development-with-docker-3-easy-steps-a7c375366b9
# https://hub.docker.com/_/wordpress/
# https://hub.docker.com/r/_/mariadb/
# https://stackoverflow.com/a/39208187/648844
# https://github.com/nezhar/wordpress-docker-compose
#
version: "2"