• Resolved wrip

    (@wrip)


    I am trying to send a POST request via API to create a new draft so I can later merge it with an existing page. I am basically trying to replicate the “Rewrite & Republish” feature. I am wanting to use the endpoint like this:

    /wp-json/wp/v2/pages?status=draft&title=My Test Page

    Do I need to pass a different value for the “status” or do I need to somehow send a reference of the existing page?

    If this is not doable via API, is there a way to do this programmatically? I just need some pointers.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I would also like information about this. Or to request this as a feature if it’s not available.

    Edit: Looked into the Yoast API and it should be possible to implement this using the duplicate_post_create_duplicate function. So not using the WP API, but with a custom implementation.

    • This reply was modified 11 months, 2 weeks ago by mmtom. Reason: Update with better info

    Update to mention that I was wrong. You can create duplicates with the Yoast API, but I don’t think you can create republish copies that way

    Thread Starter wrip

    (@wrip)

    Can someone from Yoast respond to this and let us know how to do this?

    Plugin Author Enrico Battocchi

    (@lopo)

    Hello!
    Currently there is no REST API available to duplicate posts.
    As @mmtom says, duplicate_post_create_duplicate is the function to use to create regular copies.
    To create Rewrite & Republish copies of a $post object you should use the Post_Duplicator class:

    use Yoast\WP\Duplicate_Post\Post_Duplicator;
    ...
    $post_duplicator = new Post_Duplicator();
    $return = $post_duplicator->create_duplicate_for_rewrite_and_republish( $post );


    I hope this helps!

    Thread Starter wrip

    (@wrip)

    @lopo Sorry for the late reply. That worked perfectly as expected. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I Rewrite & Republish via API or programmatically?’ is closed to new replies.