How to make requests to the XenForo API from WordPress

Use the xf_request() PHP function to make a live request to your XF site’s API. Access the full scope of your forum’s data without extra authentication to start building new features.

Once you have setup the XFtoWP plugin you can immediately make live calls that return an array of your forum data with the following function:

xf_request( $action, $route, $params = null ); 

Simply plug in the XenForo API endpoints you wish to make a request to in a GET or POST request. You also have the flexibility to add other parameters you would in any other request.

Here’s a basic example to make a GET request to the Board Index route:

$board_index = xf_request( 'GET', 'index' );
print_r( $board_index ); // read the returned array

To read any thread allowed by your API user permissions, pass the thread ID to the GET request:

xf_request( 'GET', 'thread', array(
    'route_id' => $thread_id
) );

You can create a new thread with a POST request with the following parameters:

xf_request( 'POST', 'threads', array(
    'body' => array(
        'node_id' => 1234,
        'title' => 'New thread title',
        'message' => 'My own thread content.'
    )
) );

This function makes a live request to your site on each call, so it is highly recommended you cache this data and do not run this function on every page load.

Use these helper functions to rapidly speed up your own custom XenForo to WordPress development without the hassle of a bloated framework or worrying about authentication (the plugin already handles that stuff).

Read more:

WordPress user syncing is almost ready! See what’s new in XFtoWP 1.2