Getting the IDs of a custom post type

I have made a custom post ‘case studies’ which has a number of posts.

I wish to get the IDs of each of these posts to manipulate the data, but despite looking at similar threads, I cannot piece together a way to achieve this. Something like;

foreach post oftype custom, get the id

I am making a function to display this information in the back end, here is the snippet below.

function display_meta_box( $case_study ) 
{
    if (in_array('case_studies', get_post_types()))
    {
        ...get the IDs of all posts of type 'case_studies'...
    }
    ...do other stuff with IDs...
}

2 s
2

Found the basis of the answer buried in the codex

$args = array( 'post_type' => 'case_studies');

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_ID();
endwhile;

Leave a Comment