Query for custom post taxonomy

<?php

$args = array(
'post_type' => 'my_custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => 'my_custom_category_or_term'
)
)
);
$the_query = new WP_query();
$the_query->query($args);

if($the_query->have_posts()):while($the_query->have_posts()):$the_query->the_post();

//Loop Content

endwhile; endif;
wp_reset_query();

?>

Javascript print_r

function print_r(theObj){
if(theObj.constructor == Array || theObj.constructor == Object){
document.write("<ul>")
for(var p in theObj){
if(theObj[p].constructor == Array || theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
document.write("<ul>")
print_r(theObj[p]);
document.write("</ul>")
}else document.write("<li>["+p+"] => "+theObj[p]+"</li>");
}
document.write("</ul>")
}
}

Included file URL

<?php

$file_url = 'http://' . $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(__FILE__)) . '/';

?>

Cross browser javascript events

/* ~~~~~~~~~ Event Functions ~~~~~~~~~ */

function hypEventDispatcher(){ this.events = []; }

//Add Event Listener
hypEventDispatcher.prototype.addEventlistener = function(event,callback){
this.events[event] = this.events[event] || [];
if(this.events[event]) this.events[event].push(callback);
}
//Remove Event Listener
hypEventDispatcher.prototype.removeEventlistener = function(event,callback){
if(this.events[event]){
var listeners = this.events[event];
for(var i = listeners.length-1; i>=0; --i ){
if(listeners[i] === callback){
listeners.splice(i,1);
return true;
}
}
}
return false;
}
//Dispatch Event
hypEventDispatcher.prototype.dispatch = function(event){
if(this.events[event]){
var listeners = this.events[event],len = listeners.length;
while(len--){ listeners[len](this); }
}
}
//Create Event Function - Use this as the event factory
function hypCreateEvent(eventName){
hypEventObject.prototype = new hypEventDispatcher();
hypEventObject.prototype.dispatchHypEvent = function(eventName){ this.dispatch(eventName); }
eventObject = new hypEventObject();
function hypEventObject(){ hypEventDispatcher.call(this); }
}

/* ~~~~~~~~~ Example Event ~~~~~~~~~ */

//Create Event
hypCreateEvent('hypevent');

//Add a Listener
eventObject.addEventlistener('hypevent',hypEventHandler);

//Event Handler
function hypEventHandler(){ alert('fired'); }

//Dispatch the event - this can be added anywhere in js or even in html onclick
eventObject.dispatchHypEvent('hypevent');

Function Arguments

<?php

function my_function($args = ''){
$defaults = array(
'arg1' => '',
'arg2' => false
);
$r = hyp_parse_args($args,$defaults);
extract($r);
}

function hyp_parse_args($args,$defaults = ''){
if(is_object($args)) $r = get_object_vars($args);
elseif(is_array($args)) $r =& $args;
else self::hyp_parse_str($args,$r);
if(is_array($defaults)) return array_merge($defaults,$r);
return $r;
}

function hyp_parse_str($string, &$array) {
parse_str($string,$array);
if(get_magic_quotes_gpc()) $array = stripslashes_deep($array);
return $array;
}

?>

Save plugin options multisite 3.1

<?php
//Snippet1 - New action for creating your buddypress submenu pages - replace 'create_my_submenu_page' with the name of your function

add_action(is_multisite() ? 'network_admin_menu' : 'admin_menu','create_my_submenu_page');

//Snippet2 - This is the form for submitting your plugin options. This works for plugins that only function on the main site, to account for plugins that are used on the network you may want to replace the update_options() with update_site_options() and check ahead of time to decide which to use.

<?php

function my_plugin_admin_form(){
if(isset($_POST['my_submit'])){
if(!isset($_POST['my_option']['my_display_tool'])) $_POST['my_option']['my_display_tool'] = 'false';//If no checked box in post set value to false

foreach((array)$_POST['my_option'] as $key => $value){//Add more my_option[FIELDNAME] to form for more fields
update_option($key,$value);
}
}
$my_display_tool = get_option('my_display_tool');
?>

<div class="wrap">
<h2>My Settings</h2>
<?php if(isset($_POST['my_submit'])) : ?>
<div id="message" class="updated fade">
<p>
<?php _e( 'Settings Saved', 'my' ) ?>
</p>
</div>
<?php endif; ?>
<form method="post" action="">
<?php settings_fields('my_settings'); ?>
<p style="margin-bottom:30px;">
<label style="display:block;" class="input_label">ON/OFF Switch:</label>
<br />
<input name="my_option[my_display_tool]" type="checkbox" <?php if($my_display_tool == 'true') echo 'checked'; ?> value="true" />
<!-- Add more my_option[FIELDNAME] to form for more fields -->
<span class="checkbox_text">Turn This On</span><br />
</p>
<p>
<input name="my_submit" type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div><!-- /.wrap -->
<?
}
?>

BP fix for WP 3.1

add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'MYCALLBACKFUNCTION' ); //Replace callback with the name of your function that adds the submenu page.

Count children of a custom post

<?php
echo ezb_get_page_count();

function ezb_get_page_count(){
global $aquery,$wpdb;
$query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_parent = $aquery->ezb_id AND post_type = 'ezbook'";
$post_count = $wpdb->get_var($query);
return $post_count;
}
?>

Detect mouse coordinates

//Mouse Coordinates
window.onload = ezbMouseInit;
function ezbMouseInit(){ document.onmousemove = ezbStoreCoords; }

function ezbStoreCoords(e){
var wrapWidth = ezbGetElementWidth('wrap');
var e = e;
if(e){
var mouseX = e.clientX;
var mouseY = e.clientY;
}
else{
var mouseX = event.clientX;
var mouseY = event.clientY;
}
}