• Resolved ardyonline

    (@ardyonline)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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>";
    }
    }
    ?>
    Thread Starter ardyonline

    (@ardyonline)

    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);
    	}
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get post ID?’ is closed to new replies.