Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony ajskelton

View GitHub Profile
@ajskelton
ajskelton / gist:915675de94d914bbadd9bcef965c3cbc
Created Jul 26, 2021
WordPress SQL Query for finding posts that have a specific acf value
View gist:915675de94d914bbadd9bcef965c3cbc
SELECT * FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_status = 'publish'
AND wp_postmeta.meta_value = '%ACF_FIELD_VALUE%'
ORDER BY wp_posts.ID
@ajskelton
ajskelton / gist:b358fa7e58c303314f7b2fe962a651f8
Created Apr 6, 2020
Test for pages using a specific Page Template
View gist:b358fa7e58c303314f7b2fe962a651f8
function test_for_page_template() {
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'PAGETEMPLATE.php'
)
)
);
@ajskelton
ajskelton / wp-external-image-handler.php
Last active Nov 18, 2021
WordPress External Image Handler - Add External URL image as featured image for a post
View wp-external-image-handler.php
/**
* Uploads an image from remote url and sets as featured image of the new post
*
* @param int $post_id The id of the new post
* @param string $thumbnail_url Url of the preview image hosted by BrightTalk
*/
private function image_handler( $post_id, $thumbnail_url ) {
$image_url = $thumbnail_url; // Define the image URL here
$image_name = basename( $thumbnail_url );
View Git gtree alias
alias gtree='git log --graph --abbrev-commit --decorate --date=relative --format=format:'\''%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'\'' --all'
View default-acf-flexible-content.php
add_filter( 'acf/load_value/name=content_blocks', 'default_fields', 10, 3 );
function default_fields( $value, $post_id, $field ) {
// Only add default content for new posts
if ( $value !== null ) {
return $value;
}
// Only add default content for certain post types
if ( ! in_array(
@ajskelton
ajskelton / gist:6eca1d026301a1690213a671c5e564bc
Last active Jan 30, 2019
Laravel Valet Local then Remote Images
View gist:6eca1d026301a1690213a671c5e564bc
location ~* .(png|jpe?g|gif|ico|svg)$ {
expires 24h;
log_not_found off;
root '/Users/USERNAME/.valet/Sites/mixpanel/’;
if (-f $request_filename) {
break;
}
try_files $uri $uri/ @production;
}
View gravity-forms-email-blacklist.php
add_filter( 'gform_field_validation', 'PREFIX_gravity_forms_blacklist', 10, 4 );
/**
* Added Validation check for email vs blacklist of free email accounts.
*
* @param $result array The validation result to be filtered
* @param $value string|array The field value to be validated
* @param $form object Current Form object
* @param $field object Current Field object
*
* @return mixed
View timing-app-regex-01
$regex = "/([0-9]{1,2}:[0-9]{2}:[0-9]{2})\s(AM|PM|XM)\s{0,1}\*{3}\s{0,3}\ *{1,2}LOCAL.*?([0-9]{1,2}:[0-9]{2})/";
@ajskelton
ajskelton / removeHash
Created Jun 26, 2017
Remove the hash from a url and keep the browser in the same scroll position
View removeHash
function removeHash () {
var scrollV, scrollH, loc = window.location;
if ("pushState" in history)
history.pushState("", document.title, loc.pathname + loc.search);
else {
// Prevent scrolling by storing the page's current scroll offset
scrollV = document.body.scrollTop;
scrollH = document.body.scrollLeft;
loc.hash = "";
View gist:6fd770a78bbc9b59dbf51c2fa37aa8b0
body {
font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, Helvetica, Arial, sans-serif;
}