get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ) ); return $attachment[0]; } /** * Returns an array of the attachment's properties. * * @var string URL to the image * @return array array() */ public static function get_image_from_url( $url ) { $image_id = self::get_image_id( $url ); $image = wp_get_attachment_image_src( $image_id, 'full' ); return array( 'url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'thumbnail' => $image[3], ); } /** * Helper function that gets posts and fomats them in a way so they can be used in select fields etc. */ public static function get_posts( $args ) { // Get the posts $posts = get_posts( $args ); // properly format the array. $items = array(); foreach ( $posts as $post ) { $items[ $post->ID ] = $post->post_title; } return $items; } public static function get_taxonomies() { $items = array(); // Get the taxonomies $taxonomies = get_taxonomies( array( 'public' => true ) ); // Build the array foreach ( $taxonomies as $taxonomy ) { $id = $taxonomy; $taxonomy = get_taxonomy( $taxonomy ); $items[ $id ] = $taxonomy->labels->name; } return $items; } public static function get_post_types() { $items = array(); // Get the post types $post_types = get_post_types( array( 'public' => true ), 'objects' ); // Build the array foreach ( $post_types as $post_type ) { $items[ $post_type->name ] = $post_type->labels->name; } return $items; } }