Skip to content

Instantly share code, notes, and snippets.

@vc27
vc27 / filter_admin_body_class.php
Created October 25, 2011 17:28
Add a post_type class to the admin body element. Helpful when styling custom post types.
/**
* Filter Admin body class
*
* Add a post_type class to the admin body element. Helpful when styling custom post types.
**/
add_filter( 'admin_body_class', 'vc_admin_body_class' );
function vc_admin_body_class( $admin_body_class ) {
global $post;
if ( $_GET['post_type'] )
@vc27
vc27 / build_query_url.php
Created October 25, 2011 20:26
Build Ooyala Query URL
/**
* Build Query URL
**/
function build_query_url( $params, $request_type ) {
// Add an expire time of 15 minutes unless otherwise specified
if ( is_array( $params ) AND !array_key_exists( 'expires', $params ) )
$params['expires'] = time() + 900;
@vc27
vc27 / flickr-anchor-tags
Created December 1, 2011 14:59
Remove anchor tags from flickr set
<a name="photo[0-9]{10}" id="photo[0-9]{10}"></a>
@vc27
vc27 / get_user_id_by_meta
Created December 12, 2011 21:36
Get a users id from meta_key and meta_value
/**
* Get User Id from meta_key, meta_value
**/
function get_user_id_by_meta( $meta_key, $meta_value ) {
global $wpdb;
$querystr = "SELECT $wpdb->usermeta.user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = '$meta_key' AND $wpdb->usermeta.meta_value = '$meta_value'";
$results = $wpdb->get_results( $querystr, ARRAY_N );
@vc27
vc27 / WP_Query() meta_query vs post__in
Created January 5, 2012 14:52
This is an example of two ways to query the same posts.
<?php
$array_of_data = array('Array','Of','Data');
/**
* meta_query WP_Query
**/
$query = array(
'post_type' => 'custom_post_type',
@vc27
vc27 / state_list.php
Created January 25, 2012 15:56
US states list
<?php
$state_list = array(
'AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'CO'=>"Colorado",
'CT'=>"Connecticut",
'DE'=>"Delaware",
@vc27
vc27 / has_children
Created February 11, 2012 16:31
Will check if given post_id has children in given post_type
/**
* Has Children
**/
function has_children( $post_id, $post_type ) {
global $wpdb;
$querystr = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_type = '$post_type' AND $wpdb->posts.post_parent = '$post_id' LIMIT 1";
$results = $wpdb->get_results( $querystr, ARRAY_N );
@vc27
vc27 / WP_oEmbed.php
Created February 24, 2012 23:36
Use built in WP_oEmbed for fetching data
<?php
require_once( ABSPATH . WPINC . '/class-oembed.php' );
$WP_oEmbed = new WP_oEmbed();
$provider = $WP_oEmbed->discover( $url );
$data = $WP_oEmbed->fetch( $provider, $url );
if ( isset( $data ) AND $data != false ) { print_r($data); }
@vc27
vc27 / oembed-post-meta
Created March 24, 2012 17:05
Adds a custom metabox to specified post_types allowing for youtube and vimeo oembed to be saved as hidden postmeta. Returns visalbe video url and video
<?php
/*
Plugin Name: Oembed as Post Meta
Author: Randy Hicks
Plugin URI: http://visualcoma.com
Author URI: http://visualcoma.com
Version: 0.2
Updated: 09.29.12
Description: Adds a custom metabox to specified post_types allowing for youtube and vimeo oembed
to be saved as hidden postmeta. Returns visalbe video url and video thumbnail.
@vc27
vc27 / do_color_classes.php
Created May 3, 2012 22:15 — forked from rodgerthat/do_color_classes.php
Considerations: Iterating through an array of class names and adding them to the Post Class
<?php
/************* ADDING CLASSES TO POST_CLASS **************/
// every post has a few uniquely colored elements, rather than rely on CSS nth-magic, and to keep things smooth
// and not conflict w/ trying to use jQuery nth-magic in tandem w/ the endless scroll,
// the option is to get the server to do the heavy lifting,
// ideally it would be nice to pass the array of classes to iterate thru into the filter,
/**
*
* @param $classes