Created
January 18, 2013 20:32
-
-
Save aaroneaton/4568286 to your computer and use it in GitHub Desktop.
WP:WP.com post-format fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpcom_themes_url_grabber() { | |
global $post; | |
$first_url = ''; | |
ob_start(); | |
ob_end_clean(); | |
$output = preg_match_all( '/<a.+href=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches ); | |
$first_url = $matches[1][0]; | |
if ( empty( $first_url ) ) | |
return false; | |
return $first_url; | |
} | |
function wpcom_themes_audio_grabber() { | |
global $wpdb, $post; | |
$audio = ''; | |
$query = $wpdb->prepare( "SELECT guid FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'attachment' AND post_mime_type = 'audio/mpeg' ORDER BY menu_order ASC LIMIT 1", $post->ID ); | |
$first_audio = $wpdb->get_results( $query ); | |
if ( $first_audio ) | |
return $first_audio[0]->guid; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment