Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 Embedly\Embedly(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 Embedly\Embedly(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.

share|improve this question
    
the_ID doesn't work in a function, it will echo its value, you want get_the_ID, which returns its value. also transition_post_status is a strange action to use, save_post is probably more appropriate here. –  Milo Sep 16 '13 at 2:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.