Table of Contents
How to create a table from a serialized PHP array in wpDataTables
Say you want a table of all pages in one section of your site, with each page’s title and a short preview that links to it, and no file holds that list. If you know some PHP, you can build the data yourself in a small script and let wpDataTables read the result from the script’s URL. The script can use any logic you need, such as a WordPress query, values from the URL or a call to another system.
What array format does wpDataTables read?
wpDataTables reads a serialized two-level array: an indexed array of rows, where each row is an associative array of column names and cell values.
| Array level | Becomes |
|---|---|
| Each entry of the outer, indexed array | A row |
| The keys of each inner, associative array | The column headers |
| The values of each inner array | The cells |
Your script prints the array with PHP’s serialize() function, and wpDataTables shows the data only when the URL answers with the HTTP status 200 OK. Every row needs the same keys.
How do I prepare the PHP file?
Write a PHP file that collects the data, builds the array and prints it serialized, then put the file where wpDataTables can open it by URL. This example loads WordPress, lists the child pages of the page with the ID 244, and returns the ID, the title and a 200-character preview with a link:
<?php
// Load WordPress in a standalone PHP file
include( '../wp-blog-header.php' );
// Force 200 OK, because WordPress can return 404 for standalone files
header( 'HTTP/1.1 200 OK' );
$the_query = new WP_Query( array(
'post_type' => 'page', // Only pages
'post_parent' => 244, // Only children of this page
'posts_per_page' => -1 // No limit
) );
$return_array = array();
while ( $the_query->have_posts() ) {
$the_query->the_post();
$return_array[] = array(
'Id' => get_the_ID(),
'Title' => get_the_title(),
// URL||text: shown as a link in a URL link column
'Content preview with link' => get_permalink() . '||' . strip_tags( strip_shortcodes( substr( get_the_content(), 0, 200 ) ) ) . '...'
);
}
// Print the serialized array for wpDataTables
echo serialize( $return_array );
Open the file’s URL in your browser to check it. You should see one line that starts with a:, the serialized array.
How do I create the table from the PHP file?
Create a table linked to an existing data source, choose Serialized PHP array as the source type, paste the file’s URL and click Save Changes.
- Start a linked table. Go to wpDataTables → Create a Table and click Create a data table linked to an existing data source.
- Name the table. Click New wpDataTable and type a name, for example Documentation pages.
- Choose the source type. In the Data source tab, open Input data source type and choose Serialized PHP array.
- Paste the URL. Paste the URL of your PHP file in Input file path or URL.
- Save the table. Click Save Changes. wpDataTables reads the array, creates a column for each key and shows the table preview.

To show the preview column as a link, open its column settings and set the column type to URL link. Read the column types overview for the other types.
What should I know before I use a PHP array table?
The table runs your script on every page load and shows what it returns, so the script decides how fast and how fresh the table is:
What should I remember about tables from PHP arrays?
Your PHP file returns serialize() of an indexed array of associative arrays, with a 200 OK status. Link a new table to the file’s URL with Serialized PHP array as the source type, and set the column types in the editor. Keep the keys stable, and skip caching for data that changes per user.
Where can I read more?
These pages cover other data sources and column setup: