WordPress PHP Plug-in – Post to external website via save_post command

I use stackoverflow very often and just found out in google about this one, Nice 😀

Well,
i want to save my every post i write from wordpress to my 3rd (OEXChangeble) website aswell at the same time, so i need to send the info to my website, developing a plugin iguess

Read More

I need basically the permalink (and i would be able to extract the rest of the params from my wesite), but better if i can get title, tags, permalink and description(or some of it)

i understand by my google research that all i need to do is add something like

<?php

//header of plugin   
function myFunctionThatSendsMyWebsite($url){
// procedure containing a file_get_contents('myqwebsite?url=') request to my website
}
add_action('page_post', 'myFunctionThatSendsMyWebsite', $permalink));

?>

I have problems thoug finding the name of variables i have missing (marked by ???). I know that $post contains all objet, how to extract the info from it (if there is), or if it’s complicated, it would be enought for me with permalink

Any tip?

Thanks!

Related posts

Leave a Reply

3 comments

  1. according to this link, this should work, the post id will be sent to this function automatically and you can get anything you want from a post id.

    function myFunctionToSendPost($post_ID)  {
       $post = get_post($post_ID); 
       $title = $post->post_title;
       $content = $post->post_content;
       $permalink = get_permalink($post_ID);   
       ...
    
       sendToYourServer($params);
    
       return $post_ID;
    }
    
    add_action('publish_post', 'myFunctionToSendPost');
    

    BTW, this function is called when a post is published, you can change it to happen when saved by

    add_action('save_post', 'myFunctionToSendPost');
    

    add these lines to your theme’s functions.php file.

  2. 1) While this doesn’t take advantage of the save_post feature, you can even use this code to display blog posts on a completely separate web site, as long as it’s on the same server and you have filesystem access to the WordPress directory on the original site. Simply modify the require() in the first block on this page to use the full path to your WordPress installation:

     <?php
     // Include WordPress 
     define('WP_USE_THEMES', false);
     require('/var/www/example.com/wordpress/wp-load.php');
     query_posts('showposts=1');
     ?>
    

    position your post with a while loop:

     <?php while (have_posts()): the_post(); ?>
     <?php endwhile; ?>
    

    if you want to specify which parts of the post to display use this code:

    <?php while (have_posts()): the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <p><a href="<?php the_permalink(); ?>">Read more...</a></p>
    <?php endwhile; ?>
    

    2) How about using the rss feeds from your wordpress blog?

    The following code will display a list of your feed titles with descriptions including a hyperlink to the original WordPress posts:

    <?php //  Load the XML file into a Simple XML object
    $filename = http://feeds.feedburner.com/<em>yourfeedname</em>";
    $feed = simplexml_load_file($filename);
    
    //  Iterate through the list and create the unordered list
    echo "<ul>";
    foreach ($feed->channel->item as $item) {
    echo "<li><a href='" . $item->link . "'>" . $item->title . "</a></li>";
    }
    echo "</ul>";
    echo "<li>" . $item->description . "</li>";
    ?>
    

    3) Feedburner has a free feature called BuzzBoost where you can get your posts to show in a regular HTML website that once activated you can simply copy the script that they provide into your HTML where you want the list to appear. From your feedburner account you can adjust some elements like whether the Blog title should appear or not, the format of the date, etc…

    You can also style the output using regular CSS within you websites existing CSS.

    Check it out Feedburner here:
    https://www.google.com/accounts/ServiceLogin?service=feedburner&continue=http%3A%2F%2Ffeedburner.google.com%2Ffb%2Fa%2Fmyfeeds&gsessionid=5q8jqacBluH1-AnXp08ZFw

  3. Are you trying to save a copy of the post somewhere else when they first publish the post? Or on every page view?

    You can trigger it when the post is saved by writing a plugin that implements the save_post hook:

    http://codex.wordpress.org/Plugin_API/Action_Reference

    To do it on every page, you’d probably write a plugin with a filter hook on the page (if it’s something you want other people to use) or if it’s just one site, you could add it to your theme.

    But… Are you sure you want to do this? It seems like your keepyourlinks site might be better implemented as an update service: http://codex.wordpress.org/Update_Services