Skip to content

Instantly share code, notes, and snippets.

@sorich87
Created January 24, 2012 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorich87/1667864 to your computer and use it in GitHub Desktop.
Save sorich87/1667864 to your computer and use it in GitHub Desktop.
<?php
/**
* Get a field by its id or slug
**/
public static function get_by( $field, $value ) {
global $wpdb;
switch ( $field ) {
case 'id' :
$field = 'ID';
$field_id = $value;
break;
case 'slug' :
$field = 'field_slug';
$field_id = wp_cache_get( $value, 'rs_registration_fields_slugs' );
break;
default:
return false;
}
$fields = false;
if ( false !== $field_id )
$fields = wp_cache_get( $field_id, 'rs_registration_fields' ) );
if ( false === $fields ) {
$fields = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->rs_registration_fields} WHERE $field = %s", $value ) );
if ( $fields ) {
$fields = self::clean_up( $fields );
self::update_caches( $fields );
}
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment