The MU forums have moved to WordPress.org

API for Page Creation (6 posts)

  1. pgianf
    Member
    Posted 16 years ago #

    Hi
    I'm developing a PHP function that should create a page in a specific blog. I've started from wp_insert_post and modify it to insert just pages.
    Basically I make some insert in the following tables:
    - wp_11_posts where a write page content, author, status = publish , permalink i need ....
    - wp_11_postmeta where I insert post_id, _wp_page_template, default
    - wp_11_categories where I insert post_id , 1 (category id)

    In this way the page is created i can see it in the manage section of WP Consolle but i cannot view it using the permalink. I get 404 not found.
    If, using the WP consolle i choose to edit the page and i save it without any modification than it works i can see it using the pemalink.
    So there is some info missing , i need to store some more info somewhere.
    I've tried to follow the consollo flow but it is difficult to understand page-new.php and page.php flow.
    Any suggestions?
    thanks
    Paolo

  2. theapparatus
    Member
    Posted 16 years ago #

    Before you get any further, you may want to upgrade. *_categories is no longer.

  3. pgianf
    Member
    Posted 16 years ago #

    it's difficult for me to male un upgrade of the whole site at this moment. could you pls give me an help on this problem. I really cannot figure it out

  4. andrea_r
    Moderator
    Posted 16 years ago #

    look in wp-includes/wpmu-functions.php where it sets up a new blog. See how it sets up the default About page.

  5. beaulebens
    Member
    Posted 16 years ago #

    Sounds like you're not creating the required rewrite rules for your new page, so Wordpress doesn't know that it exists as far as handling "public" requests for it. As andrea_r suggests, check out how the default About page is created, or just look further into the rewrite rules stuff (which I'll admit is a bit complex for me right now :)

  6. pgianf
    Member
    Posted 16 years ago #

    I've found the mail problem. the global variable $wpdb contains all prefix and settings for blog number 1, I've tried to call "switch to blog" in order to load my blog tables but no effect , so i manually filled $wpdb variable like this:
    $wpdb->prefix = $table_prefix;
    $wpdb->blogid = $new_blog;
    $wpdb->posts = $table_prefix . 'posts';
    then it started working.
    So I have created the page. The strange thing is the the guid i insert in the posts table is not respected. Pages responds to http://host/blogs/myblog/index.php?pagename=mypage.
    I would like to change this permalink template to
    http://host/blogs/myblog/mypage .

About this Topic