I just found the magnificent wp_insert_post function and have a few basic question about it. *For reference I used this on a multisite install for a number of blogs running theme_x. I simply wanted to add a page to each blog (without having to do it through WP Admin). This seems to have mostly-worked though I'm not sure I'm using it for its intended purpose?

  1. What happens if the specified page title already exists on several blogs? Does it a) terminate the function b)rename in typical WP fashion to "page-name-2" format, or c) something else?
  2. Should I remove the code from the theme template now that I have done what I needed to? I'd like to leave it in just incase more blogs are added which use this theme but I'm wondering if it creates unnecessary database overload (does it get run every page load)?
  3. The page doesn't appear anywhere in WP admin? Though all blogs using this theme do indeed resolve to the newly-added page like so ... URL/newly-added-page. This is fine for me in this instance, but it makes me think I'm not using the function "properly" (I kinda expected a new page in WP Admin also)
  • Well by the looks of my blogs, I've just answered most of my own questions! - Yes is the functions is left in the template it creates a new page on every load. - If a page name exists already, it indeed renames in the standard WordPress format (page-name-2, page-name-3, page-name-4, etc) Now to remove all the extra pages I did not want! – TheLoneCuber Apr 3 '11 at 8:06
  1. Wordpress just adds a new entry, the title is not unique, but there is a field guid which is. Permalinks do get an incremental number.
  2. Yes, you should remove it from your theme, you'd better write your own plugin for this kind of stuff.
  3. I don't totally understand what you mean, is there no menu entry in the admin? That's because it's not a plugin. Does it not show up in the theme editor? Then the file probably doesn't have an appropiate header, is not in the correct place or not correctly named.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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