The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Add ajax to new post page (2 posts)

  1. ellvix
    Posted 3 years ago #


    I'm trying to add a simple ajax callback to my 'new post' page.

    When I create new posts, I have info that is easy for a server to fetch, but a hassle for me to type out. I'd like to be able to trigger the call, and fill my blank post up with the fetched text.

    This doesn't sound easy, and so a fallback is for me to just print the text out somewhere on the page for me to copy paste to the new post. I could even write this as a separate plugin with it's own page, but the fewer steps I can have between clicking the trigger and filling my post with the fetched text, the better.

    Work I've done so far:

    I've poured over the docs for adding ajax to an admin page. I've tried to add or include the various test calls straight to the edit-form-advanced page (no luck). I've tried adding simple text / javascript to the edit-form-advanced page (that works just fine). I seem unable to call a php callback from the new post page.

    Any help is welcome, including "Don't do it that way. You'll break wordpress".

  2. bcworkz
    Posted 3 years ago #

    Ajax calls from the editor would be difficult. I think you want to explore the Shortcode_API. You can pass the specifics as parameters to the shortcode, and then the shortcode handler can gather the details and echo them out in the post.

    The one thing that may be a problem here is the handler is called each time the post is viewed, the contents it produces is not stored in the post contents in the DB.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.