Get posts for custom post type with WP_Query

Assuming your custom post type is named “job_posting”, you just need to change your query to read:

$query = new WP_Query( array( 'post_type' => 'job_posting' ) );

This can be found in the official documentation.

There’s a lot more parameters you might like to use too – you can find a full list in the documentation I linked to. Some I’d recommend considering would be posts_per_page (so you don’t get everything returned at once), and setting post_status to ‘publish’ just in case any draft/private posts get returned (which they shouldn’t anyway, but I like to be safe 😉 ).

Leave a Comment

tech