Open WordPress ‘Add New Post’ admin page with parameters set via $_GET

I want to launch my web browser from an automation tool I use and open WordPress “Add Nwe Post” page in the admin area with specific title and content (it varies everytime, I generate it dynamically on my local machine).

I know that I can use http://blog.mysite.com/wp-admin/post-new.php?post_title=sometitle

Read More

This is fine. However, if I try to set the content of the post, using “content” url parameter, it can be only plain text. If I set HTML, it is escaped automatically. Is there a way to set the HTML content of the post?

Also, I don’t know how I can set page categories via url parameters too?

P.S.: I don’t want to create programatically a new post, but just to have the Add Post page open with prefilled fields.

Related posts

Leave a Reply

1 comment

  1. The problem is that $content is a reserved variable in WordPress, you have to use another name. Here, I have used $pre_content:

    enter image description here

    <?php
    /**
     * Plugin Name: T5 Editor content by request
     * Description: Default text for post content from GET variable <code>pre_content</code>.
     * Author:      Fuxia Scholz
     * Version:     2012.06.30
     */
    
    /*
     * See wp-admin/includes/post.php function get_default_post_to_edit()
     * There are also the filters 'default_title' and 'default_excerpt'
     */
    add_filter( 'default_content', 't5_content_by_request', 10, 2 );
    
    /**
     * Fills the default content for post type 'post' if it is not empty.
     *
     * @param string $content
     * @param object $post
     * @return string
     */
    function t5_content_by_request( $content, $post )
    {
        if ( ! empty ( $_GET['pre_content'] )
            and current_user_can( 'edit_post', $post->ID )
            and '' === $content
        )
        {
            return $_GET['pre_content'];
        }
    
        return $content;
    }