I created a new post type fr_news
for adding news to a site. The user inputs a URL, and what I want it to do is use the Embed.ly API to display the news. I’ve got the API side figured out.
Here’s the working API code:
global $embedly_options;
$embedly_options = get_option('embedly_settings');
$api = new EmbedlyEmbedly(array( 'key' => $embedly_options['key'], 'user_agent' => 'Mozilla/5.0 (compatible; mytestapp/1.0)' ));
$fr_news_url = $post->fr_news_url;
$embedly_resp = $api->oembed( $fr_news_url );
Which outputs this when when print_r( $embedly_resp )
it:
stdClass Object (
[provider_url] => http://www.ibtimes.com
[description] => House Minority Leader Nancy Pelosi, D-Calif., said there will be strong opposition if House Republicans don't make their recent concurrent resolution favorable to achieving a compromise.
[title] => Pelosi: 'Strong Negative' Reaction If GOP Won't Compromise
[author_name] => Laura Matthews
[thumbnail_width] => 770
[url] => http://www.ibtimes.com/government-shutdown-2013-pelosi-warns-strong-negative-reaction-if-republicans-dont-go-compromise
[thumbnail_url] => http://s1.ibtimes.com/sites/www.ibtimes.com/files/styles/v2_article_large/public/2013/09/10/pelosi-2013.jpg
[author_url] => http://www.ibtimes.com/reporters/laura-matthews
[version] => 1.0
[provider_name] => Ibtimes
[type] => link
[thumbnail_height] => 506
)
However, instead of pulling on page load, want to add to pull from API and add to post_meta every time the URL changes changes:
add_action( 'transition_post_status', 'get_fr_news_embedly', 9 );
function get_fr_news_embedly( $new_status, $old_status, $post ) {
if ( $new_status != 'trash' && $post->type == 'fr_news' ) {
// Post is not in trash and is fr_news
global $embedly_options;
$embedly_options = get_option('embedly_settings');
$api = new EmbedlyEmbedly(array( 'key' => $embedly_options['key'], 'user_agent' => 'Mozilla/5.0 (compatible; mytestapp/1.0)' ));
$fr_news_url = $post->fr_news_url;
$embedly_resp = $api->oembed( $fr_news_url );
if ( ! update_post_meta ( $post->id, 'fr_news_objs', $embedly_resp ) ) add_post_meta( $post->id, 'fr_news_objs', $embedly_resp );
}
}
I’m pulling and displaying it this way:
<?php $embedly_resp = get_post_meta( the_ID(), 'fr_news_objs', true ); ?>
<?php print_r( $embedly_resp ); ?>
to no avail.