• Resolved Younes

    (@vanbom)


    Hello everyone,
    I am looking for a way to allow the user to add child pages to a page to select directly in my plugin.
    is there a hook that can do that? or, I have to update the database directly?
    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Are you looking for the code to specify the parent page? Or a way to let the user select a page?

    Assuming the the first, you’ll use the 'post_parent' parameter. It takes the ID of the post you want to act as the parent to the post/page you are creating.


    // Create post object
    $args = array(
    'post_title' => 'TITLE',
    'post_content' => 'PAGE CONTENT',
    'post_status' => 'publish',
    'post_parent' => 'ID OF THE PARENT PAGE'
    );

    // Insert the post into the database
    wp_insert_post( $args );

    https://developer.www.ads-software.com/reference/functions/wp_insert_post/

    Thread Starter Younes

    (@vanbom)

    thank you @corypina,

    this is in detail what I want to do:

    I want to create a plugin, where, the user can do this:
    select a page (in a combobox for example), and after, select one or more pages (in a checkbox list) and define them as child pages.
    otherwise, I want to offer the ‘Page Attributes -> Parent’ option in my Plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘a hook to add child pages directly’ is closed to new replies.