EDITED question to be more specific and added bounty in hopes someone has a solid coded solution:

So, here is an interesting task I have been trying to find a solution for. I have added a bounty which I will award to the best solution in the form of working code.

What I am trying to do here is utilize wordpress as the default CMS for a website for all standard content. The solution I am looking for involves a specific "custom post type" I want to have (called: locations). For this custom post type I am specifically looking to have the posts and content automatically populated based upon the city list data and content per city from this wikipedia page: http://en.wikipedia.org/wiki/List_of_cities_in_Los_Angeles_County,_California

Now, I realize that one could essentially extract all of the information for each of the cities and use some type of import method to get each Wikipedia city into wordpress (each as a separate post) however this is not what I am after.

My requirements and this bounty relates to three specific goals/components:

1) I need all the posts (locations) and their associating content to come from Wikipedia through their API (example below). This means that whenever a post related to the custom post type "locations" is requested the Wikipedia content is delivered (this relates to the main admin area as well as the public website). Data coming from Wikipedia should be cached locally for 24 hours to ensure the data remains current with that of Wikipedia.

2) For the admin and website visitor the source of any Wikipedia content remains transparent. Important here is that the admin retains the ability of editing any of these posts. This means that When the post editor is called for such a location (post) wikipedia content is pulled in realtime and loaded into the post editor. Once the admin saves the post wordpress would no longer request or update the content of this specific post from Wikipedia but will rather deliver it locally from the WP database.

3) It is important to note that from a theme developers point of view no changes should be required at all. This means that all typical elements of requesting a post or custom field needs to remain and function correctly. Finally, it is very important that specific content "sections" of the Wikipedia page can be assigned to specific custom fields used by Wordpress when calling templates or the admin editor.

EXAMPLE Wikipedia API Request Listing all Locations: http://en.wikipedia.org/w/api.php?action=parse&format=xml&pageid=18614608&prop=wikitext|iwlinks|headitems|links|displaytitle|text

EXAMPLE Wikipedia API Request for the content of a specific location page: http://en.wikipedia.org/w/api.php?action=parse&format=xml&page=Los_Angeles&prop=wikitext

  • There are too many issues in this question. You have to break it apart into separate pieces for each aspect. Since I've answered the pre-populate if empty part here, make the rest of it (cron job to create posts, active/inactive, etc.) separate questions. If you need help calling and parsing the results of the API call that's another question again.
    – marfarma
    Commented Sep 26, 2011 at 21:08
  • FYI - Mentioned bounty not assigned.
    – marfarma
    Commented Sep 28, 2011 at 17:31
  • So, in addition to the solution provided by my answer, you're looking for 1) code that will create the pages for each location from the 'listing all locations' api call, 2) a custom post definition that maps to the wikipedia location content sections, 3) code that maps the wikipedia specific location api call to that custom post type, and 4) 24 hour persistent caching of the location content? Really? Still way too much for a single question.
    – marfarma
    Commented Sep 28, 2011 at 17:42
  • Agreed - in current form this is "do a job for me for free", not a question. Please break this done into specific answerable questions that you have trouble with, don't post your spec and expect someone to work on it.
    – Rarst
    Commented Sep 28, 2011 at 19:03

1 Answer 1


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;

Not the answer you're looking for? Browse other questions tagged or ask your own question.