0

I want to use wordpress content in external mobile app. I need an URL address to get content from function located in functions.php for example:

function test()
{
     return 'it works';
}

What I need is an url address (http://example.com/something) which will return a value from function test. I hope that I wrote it clearly. Sorry for my language mistakes.

1 Answer 1

0

You can check for the presence of a specific query variable, so http://www.example.com?my_listener=test. You check for this on the init hook and if it isn't there you just quit early and WP goes about it's business. If it is there, you can then do something, just don't forget to exit at the end or the full page loads and that can mess up the response you are trying to send to your app.

    function wpa_91930() {
        // if query var is not present just return
        if ( ! isset( $_REQUEST['my_listener'] ) || 'test' != $_REQUEST['my_listener'] )
            return;

        // send response
        echo "it works";

       // don't forget to exit when you are done
       exit;
    }

    add_action( 'init', 'wpa_91930' );
3
  • Thank you, it works. Maybe you've got some idea to change url format from example.com?my_listener=test to example.com/test ? It just looks better :) Commented Mar 22, 2013 at 12:42
  • This might help with creating pretty URLs: wordpress.stackexchange.com/questions/12965/… Commented Mar 22, 2013 at 13:59
  • If it is just an app that is collecting data, how the URL looks doesn't seem that important. But following Pat's link, should get you the appropriate rewrite rules. Commented Mar 22, 2013 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.