Skip to content

Instantly share code, notes, and snippets.

View bjorn2404's full-sized avatar

Björn Holine bjorn2404

View GitHub Profile
@bjorn2404
bjorn2404 / get_posts_and_future_posts.php
Last active January 3, 2016 12:39
WordPress - get posts from beginning of time to 30 days in the future with custom meta date values. Useful for an events post type.
<?php
$upcoming_events = date( 'Ymd', strtotime( '+30 days' ) ); // Today + 30 days.
$events_args = array(
'posts_per_page' => 10,
'post_type' => 'event', //Events post type
'post_status' => 'publish,future', //Also includes scheduled posts
'orderby' => 'meta_value',
'meta_key' => 'start_date',
@bjorn2404
bjorn2404 / gravity_forms_date_filter.php
Created January 20, 2014 21:55
WordPress - convert Gravity Form date format string to a string without extra characters when submitting to a post type. In my situation I wanted to go from yyyy/mm/dd to yyyymmdd for Advanced Custom Fields compatibility
<?php
/**
* Filter GF date and convert to compatible ACF date string
* $form['id'] is the id of the Gravity Form and $post_data['post_custom_fields']['event_date'] is the custom field
*/
add_filter('gform_post_data', 'custom_update_gf_date', 10, 3);
function custom_update_gf_date($post_data, $form){
@bjorn2404
bjorn2404 / gist:276741cce5cacd35a4ab
Created July 2, 2014 19:59
Remove duplicate WordPress post meta
<?php
require_once('../../../wp-load.php'); //File was temporarily placed in the theme
define( 'WP_DEBUG_DISPLAY', true );
ini_set( 'display_errors', true );
$allposts = get_posts('numberposts=-1&post_type=guide&post_status=any'); //Post query
$keys = array('address', 'address2', 'city', 'state', 'zip'); //Add post meta keys here
foreach ( $keys as $key ) {
foreach( $allposts as $postinfo) {
@bjorn2404
bjorn2404 / wordpress_remote_images
Created May 21, 2015 20:51
WordPress load remote images if they don't exist on the local development server htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/(.*)$
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads/%1 !-f
RewriteRule ^wp-content/uploads/(.*)$ http://www.remotesite.com/wp-content/uploads/$1 [R=301,L]
</IfModule>
@bjorn2404
bjorn2404 / php_format_address
Last active August 29, 2015 14:25
PHP format street address
/**
* Format a street address
*
* @param array $address Address.
*
* @return null|string
*/
function format_address( $address ) {
$formatted_address = null;
@bjorn2404
bjorn2404 / favicon.txt
Created November 10, 2015 19:55
Imagemagick favicon
convert favicon.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
\( -clone 0 -resize 128x128 \) \
\( -clone 0 -resize 256x256 \) \
-delete 0 -alpha off -colors 256 favicon.ico
@bjorn2404
bjorn2404 / nginx.conf
Created March 28, 2016 20:12
WordPress load remote images if they don't exist on the local development server NGINX. vagrant provision after editing site conf file.
location ~ ^/wp-content/uploads/(.*) {
if (!-f $request_filename) {
rewrite ^/wp-content/uploads/(.*)$ http://www.remotesite.com/wp-content/uploads/$1 redirect;
}
}
@bjorn2404
bjorn2404 / wp_kses_post_tags.php
Last active April 22, 2024 15:08
WordPress allow iFrames with wp_kses_post filter
<?php
/**
* Add iFrame to allowed wp_kses_post tags
*
* @param array $tags Allowed tags, attributes, and/or entities.
* @param string $context Context to judge allowed tags by. Allowed values are 'post'.
*
* @return array
*/
@bjorn2404
bjorn2404 / page-template.php
Last active May 11, 2018 04:50
CSL manual front-end filters markup example
<div class="bh-sl-container">
<div class="bh-sl-form-container">
<form id="bh-sl-user-location" method="post" action="#">
<div class="form-input">
<label for="bh-sl-address">Enter Address or Zip Code:</label>
<input type="text" id="bh-sl-address" name="bh-sl-address" />
</div>
<button id="bh-sl-submit" type="submit">Submit</button>
@bjorn2404
bjorn2404 / functions.php
Last active May 11, 2018 05:41
CSL manual front-end filters register example
<?php
/**
* Manually add categories for static data.
* The property ('category' below) should match the property/attribute name in your JSON or XML data.
* The value ('category-filter' below) should match the ID of the HTML container element around the input fields.
*/
function bh_sl_manual_categories() {
?>
<script>