How to get all post ID in a certain category? and put the result in a array variable?
$var = array(1,6,11);
where 1, 6, 11 are the postID of specific category.
How to get all post ID in a certain category? and put the result in a array variable?
$var = array(1,6,11);
where 1, 6, 11 are the postID of specific category.
Something like:
<?php
$cat = 47; //category id
$posts=get_posts('showposts=-1&cat='. $cat);
if ($posts) {
foreach($posts as $post) {
echo "<pre>"; print_r($post->ID); echo "</pre>";
}
}
?>thanks MichaelH!
it enlightens me, it really helps!
Below is the exact code to get it in the array format,
<?php
$cat = 47; //category id
$posts=get_posts('showposts=-1&cat='. $cat);
if ($posts) {
$cat_post_ids = array();
foreach($posts as $post) {
array_push($cat_post_ids, $post->ID);
}
print_r($cat_post_ids);
}
?>This topic has been closed to new replies.