Skip to content

Instantly share code, notes, and snippets.

View bjorn2404's full-sized avatar

Björn Holine bjorn2404

View GitHub Profile
@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 / 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 / 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 / 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 / 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',