WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Force a post to "create" itself when clicking Add New? (3 posts)

  1. f00bar
    Member
    Posted 4 years ago #

    Hey everyone, just a quick one (and hopefully easy...)

    I wondered if it was possible to "force" a post to enter into draft mode when you click Add New. I have put in a little jQuery code in the admin head which automatically populates the title with a default text but as far as I can gather, the post only enters draft mode when you tab out of the title area into the main text box.

    You may be asking why I want this to happen. Well, my client has asked for a bespoke custom meta box with image upload. However, if he was to upload the image first without actually typing anything (therefore not technically creating the post) the Save button next to the image uploader will not work, as it performs the same action as Publish.

    So, what I'm asking is if it's possible to actually create the post as soon as Add New is clicked, rather than it waiting until content is entered...

    Thanks in advance
    Michael

  2. s_ha_dum
    Member
    Posted 4 years ago #

    Any accidental click on 'Add New' would then create a new post. I can see potential for a lot of spurious posts. But... your jQuery already populates the title. Have the same script reset focus onto the post body after it sets the title and see what happens. I've never tried anything like this so I'm guessing but that is the first thing I'd try.

  3. f00bar
    Member
    Posted 4 years ago #

    Thanks for the response.

    After some testing, I programmed this:

    $(function(){
    if($("#title").val()==""){
      $("#normal-sortables").hide();
    }
    
    $("#title").keyup( function(){
      if($("#title").val()!=""){
         $("#normal-sortables").fadeIn("slow");
      }
    });
    });

    On entering the add new post page. This would hide all extra boxes until the user put some content into the title box. If the user deleted the title after, the boxes would disappear again :)

Topic Closed

This topic has been closed to new replies.

About this Topic