• Resolved hermit1

    (@hermit1)


    Hi folks,

    I am building a plugin and very new to wordpress ecosystem. First of all I want to thank all community member to build something like wordpress. (coming from nodejs background).

    What I want from my plugin is, when a user install this plugin, the plugin should automatically create a post / page , like the way we do from UI by clicking “Add new” submenu from “Page” menu. I want to do the same thing from my code.

    Any reference or help is highly appreciated.

    Thanks.

    • This topic was modified 5 years ago by hermit1. Reason: grammetical mistake
Viewing 4 replies - 1 through 4 (of 4 total)
  • catacaustic

    (@catacaustic)

    Tis page is about creating database tables when you activate a plugin, but you can take out that part of things and add yoru own code to create pages.

    https://codex.wordpress.org/Creating_Tables_with_Plugins#Calling_the_functions

    To create pages (or posts or any other post type that you want to), you can use wp_insert_post().

    The only thing to be careful of is that you need to keep track of if the pages have been created or not, otherwise your plugin will create new pages every time someone activates it, so if they deactivate for any reason then reactivate it, it will still try to create the pages again unless you tell it not to.

    Thread Starter hermit1

    (@hermit1)

    Hi @catacaustic

    Thank you for reply. I think I am confused or mistaken. I tried this solution and glad that it worked but it created “Post” not “Page”. What I mean that from the UI I can see there are two sections “Post” and “Page”. When I used wp_instert_post() api, it created a new post in “Post” section but what I wanted was to create new page.

    It is the same function to insert a page so if you’re getting that you’re doing it right.

    To make it a page, you need to look at the arguments that you give to that function. For this one case, you’d set ‘post_type’ as ‘page’ and That will create a page instead of a post, which is the default when nothing else is supplied.

    Thread Starter hermit1

    (@hermit1)

    Perfect. It worked. thank you very much.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Creating new page using WordPress plugin’ is closed to new replies.