WordPress.org

Forums

Quick method for adding Child page from Parent (4 posts)

  1. ryansigg
    Member
    Posted 1 year ago #

    In the never-ending hunt to make WP even easier and quicker for clients, I'm looking for a method to add Child posts/pages/CPTs from a parent page (I've searched the forum, but it seems almost every "child page" topic deals with adding child pages to the menu).

    I don't even know if such a thing is really possible from one page to another... I have not seen anything like this, aside from plugins which automatically add multiple pages at once (like "Simple add pages or posts")

    It doesn't need to be an in-page, AJAXy sort of thing; just a URL to a new page with the Parent already set would be great.
    Perhaps there is a way to add a parameter to the "Add New" URL (wp-admin/post-new.php?post_type=custom_type_here) to specify a parent URL?
    Or perhaps there is a plugin that I have not found in all my searching?

    Thanks!

  2. bcworkz
    Member
    Posted 1 year ago #

    So you want something like a button or link on a page that, when clicked, causes a child page to be created where the referring page (page containing the link) is the parent of that child page, correct?

    That can be done. It does sort of need to be AJAXy in order for the script being executed to have access to WP functions and the DB. If you really want a new page load to occur, there is a GET/POST interface that is implemented much like AJAX except no javascript is needed.

    The initiating link needs to pass the parent page ID and an 'action' value that defines the action hook the handler function would hook into. The link must point to wp-admin/admin-post.php.

    Your handler is defined on a plugin file or functions.php. It is added as a callback to an action hook that is defined in part by the action URL parameter and concatenated to 'admin_post_' in the same way as is done with AJAX.

    The handler can then create a new child page with wp_insert_post(), specify as the parent ID. If the page uses a particular template, add the file path to postmeta under the key '_wp_page_template'.

    Be sure you include basic security measures to prevent exploits. The new page link should include a nonce. The handler needs to confirm the user is properly logged in by checking the nonce. Also confirm the user has the capability to create a page.

  3. ryansigg
    Member
    Posted 1 year ago #

    Thanks for your answer...

    I think that is going to be beyond my present understanding of WP; rather, it would take more time to learn/implement than the benefit it would provide...

  4. RobertBrisbane
    Member
    Posted 1 year ago #

    Hi,
    I just wanted to follow up on this thread and was wondering if there had been any progress?

    I found this snippet a while ago but it doesn't quiet do the trick:
    http://wordpress.stackexchange.com/questions/44324/creating-new-page-with-pre-defined-parent-page

    also see:
    http://wordpress.org/support/topic/new-child-post-button-from-parent-post-without-using-attribute-drop-down?replies=1#post-5698454

Topic Closed

This topic has been closed to new replies.

About this Topic