VPS business hosting starting at $29.95/24/7 premium technical support

Standalone script to print all published post IDs in WordPress

header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
define( 'SHORTINIT', true );
require( 'wp-load.php' );
$qr = 'SELECT * FROM `'.$wpdb->prefix . 'posts` where `post_type`="post" and `post_status`="publish"';
$posts = $wpdb->get_results( $qr);
//$pr = implode(",",array_column($posts,"ID"));
$pr = json_encode(array_column($posts,"ID"));
echo $pr;

Author: Harshvardhan Malpani

PHP Developer based in New Delhi, India. Working as a freelance web developer providing server deployment, website development and maintenance services.

Leave a Reply

Your email address will not be published.