Integrating custom API for post content into Admin interface & Public Website [closed]

To pre-populate the post if it’s empty hook the the_editor_content filter — this allows you to check if the post has any content. If not, then you can call the Wikipedia API and pull it in – -this will delay the post editor load, so a simple cache is implemented – depending on your use case, you may need to create a persistent cache (by creating some database location to store the data — this cache is only for the current user’s session.

Add something like this to your functions.php file. (I haven’t tested this. You’ll have to test and debug this code if it doesn’t work immediately.)


add_filter('the_editor_content', 'preset_content');

function my_editor_content( $content ) {
  global $post;

  // check if content is empty

  if ( $post->post_content == '' and $post->post_type == 'your_post_type' ) {

    // pull post metadata to determine location

    $location = get_post_meta($post->ID,'your_location_meta_field_name',true);

    // results buffered in an array - only check wikipedia if not found

    if (!isset($wikipedia_content[$location]) || $wikipedia_content[$location] == '') {

      // return wikipedia API results here
      $wikipedia_content[$location] = your_wikipedia_api_call($location);

    }

    $default_content = $wikipedia_content[$location];

  } else {
    $default_content = $post->post_content;
  } 

  return $default_content;
}