• Hallo,

    I need to get the embeded objects for a couple of posts, because I want to display some of them at the front page.

    How to do this has already been asked here in this forum. In that post it was suggested to use $post->post_content and to search for <video> (in my case: <iframe> using preg_match_all.

    An alternative solution would be to use raw SQL like in the following function:

    function get_embeds ($post_id) {
    	global $wpdb;
    	$prefix = $wpdb->get_blog_prefix(BLOG_ID_CURRENT_SITE);
    	$sql_statement = "
    		SELECT meta_value
    		FROM " . $prefix . "postmeta
    		WHERE post_id = " . $post_id . "
    		AND meta_key LIKE '_oembed%'
    		";
    	return $wpdb->get_col($sql_statement);
    }

    Which way is cleaner?

    Philipp

  • The topic ‘What's the best way to get the embedded objects of a post?’ is closed to new replies.