Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
rileypaulsen / Zippopotamus API Call
Created July 29, 2013 17:11
check against the zippopotamus API
function checkZipCodeState(zip){
jQuery.ajax(
'http://api.zippopotam.us/us/'+zip,
{
success:function(data){
return data;
}
}
);
}
@rileypaulsen
rileypaulsen / Upcoming Events from All-In-One Events Calendar
Last active December 20, 2015 08:39
get x number of upcoming events from the all in one events calendar
function get_ai1ec_upcoming_events($number = 3){
global $wpdb;
$todaysDate = date('Y-m-d G:i:s');
$upcomingEvents = $wpdb->get_results(
"SELECT
{$wpdb->prefix}posts.post_title,
{$wpdb->prefix}posts.ID,
{$wpdb->prefix}ai1ec_event_instances.start,
{$wpdb->prefix}ai1ec_event_instances.end
FROM
@rileypaulsen
rileypaulsen / Force make_clickable() to generate target="_blank" links
Last active May 25, 2022 02:34
extend WordPress's make_clickable function to have target="_blank"
@rileypaulsen
rileypaulsen / Define console.log() for IE
Last active December 19, 2015 22:08
define a console function fallback for IE to avoid JavaScript errors
if (typeof(console) === 'undefined') {
console = {
log : function(data){},
table : function(data){}
};
}
@rileypaulsen
rileypaulsen / Shortcodes with get_template_part()
Created July 17, 2013 08:17
use get_template_part() in a shortcode without outputting the html arbitrarily due to the behind the scenes 'require.'
add_shortcode('donation-posts', 'fnDonatePosts');
function fnDonatePosts($attr, $content)
{
ob_start();
get_template_part('donation', 'posts');
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
@rileypaulsen
rileypaulsen / Capitalize Field in MYSQL
Created July 10, 2013 20:40
capitalize the first letter of mysql entry
UPDATE wp_postmeta set meta_value = CONCAT(UCASE(SUBSTRING(meta_value, 1, 1)), LOWER(SUBSTRING(meta_value FROM 2))) WHERE meta_key='firstname'
@rileypaulsen
rileypaulsen / Change Roles
Last active December 19, 2015 13:09
add/remove capabilities to user roles
$edit_editor = get_role('editor');
$edit_editor->add_cap('add_users');
$edit_editor->add_cap('create_users');
$edit_editor->add_cap('delete_users');
$edit_editor->add_cap('edit_users');
$edit_editor->add_cap('list_users');
$edit_editor->add_cap('edit_theme_options');
@rileypaulsen
rileypaulsen / FTP Info in WP-Config.php
Last active December 19, 2015 13:09
ftp info for wp-config.php
define( 'FTP_HOST', '###HOST##' );
define( 'FTP_USER', '###USERNAME###' );
define( 'FTP_PASS', '###PASSWORD###' );
@rileypaulsen
rileypaulsen / Gravity Forms User Capability
Last active December 19, 2015 13:09
add gravity forms capability to editors
function add_grav_forms(){
$role = get_role('editor');
$role->add_cap('gform_full_access');
}
add_action('admin_init','add_grav_forms');
@rileypaulsen
rileypaulsen / Order By Meta - get_posts()
Last active December 19, 2015 13:09
order results by meta value in get_posts()
$args = array(
'post_status' => 'publish',
'post_type' => '###POSTTYPE###',
'meta_key' => '###METAKEY###',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);