Skip to content

Instantly share code, notes, and snippets.

@PareshRadadiya
Created September 19, 2019 19:01
Show Gist options
  • Save PareshRadadiya/5867c8929ab1ca72af5c2dc521bcdaa3 to your computer and use it in GitHub Desktop.
Save PareshRadadiya/5867c8929ab1ca72af5c2dc521bcdaa3 to your computer and use it in GitHub Desktop.
WP_Query with fields test
<?php
add_action('init', 'test_wp_query');
function test_wp_query() {
$time_start = microtime(true);
$query = new WP_Query([
'nopaging' => true,
'post_type' => 'post',
'fields' => 'ids'
]);
if ( $query->have_posts() ) {
while( $query->have_posts()) {
$query->the_post();
the_ID();
}
}
$time_end = microtime(true);
//execution time of the script
echo '<b>Total Execution Time:</b> '.$time_end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment