I want to get all published posts in wordpress, I tried
<div class="pppp" style="display:none">
<?php $post_ids = get_posts(array(
'fields' => 'ids', // Only get post IDs
));
var_dump($post_ids);
?>
</div>
but return only 5 last post ids.
array(5) { [0]=> int(35102) [1]=> int(35097) [2]=> int(35094) [3]=> int(33281) [4]=> int(33279) }
I want to know how can I get all postids of my wordpress sites?
Reference: https://developer.wordpress.org/reference/functions/get_posts/#source
function get_posts( $args = null ) {
$defaults = array(
'numberposts' => 5,
'category' => 0,
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
'exclude' => array(),
'meta_key' => '',
'meta_value' =>'',
'post_type' => 'post',
'suppress_filters' => true
);
....
}
so you should add something to your array like
get_posts(array(
'fields' => 'ids', // Only get post IDs
'posts_per_page' => -1
));
Note: 'numberposts
' and 'posts_per_page
' can be used interchangeably.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With