Skip to content

The Job Post Loop

The job post loop is the primary way to display a list of jobs using template functions. It follows the WordPress have_posts() / the_post() pattern.

<?php
// Always check the function exists (in case the plugin is deactivated)
if (function_exists('have_jobposts') && have_jobposts()):
// Loop through each job post
while (have_jobposts()): the_jobpost();
// Display job data
the_jobpost('title');
endwhile;
else:
echo "No job posts available.";
endif;
?>
<?php if (function_exists('have_jobposts') && have_jobposts()): ?>
<p><?php echo get_jobpost_count(); ?> open positions</p>
<?php while (have_jobposts()): the_jobpost(); ?>
<article class="job-post">
<?php if ($logo = get_jobpost('logo')): ?>
<img src="<?php echo $logo; ?>"
alt="<?php the_jobpost('name'); ?>" />
<?php endif; ?>
<h3>
<a href="<?php echo get_jobpost('permalink'); ?>">
<?php the_jobpost('name'); ?>
</a>
</h3>
<p><?php the_jobpost('excerpt'); ?></p>
<ul>
<?php if ($workplace = get_jobpost('workplace')): ?>
<li>Location: <?php echo $workplace; ?></li>
<?php endif; ?>
<?php if ($type = get_jobpost('type')): ?>
<li>Type: <?php echo $type; ?></li>
<?php endif; ?>
<?php if ($deadline = get_jobpost('deadline')): ?>
<li>Deadline: <?php echo $deadline; ?></li>
<?php endif; ?>
</ul>
</article>
<?php endwhile; ?>
<?php else: ?>
<p>No job posts available.</p>
<?php endif; ?>

Pass an integer to have_jobposts() to limit how many jobs are displayed:

<?php if (have_jobposts(10)): ?>
<?php while (have_jobposts(10)): the_jobpost(); ?>
<!-- Shows max 10 jobs -->
<?php endwhile; ?>
<?php endif; ?>

Use the second parameter for offset:

<?php
// Skip the first 10, show the next 10
if (have_jobposts(10, 10)):
while (have_jobposts(10, 10)): the_jobpost();
the_jobpost('title');
endwhile;
endif;
?>

When showing multiple feeds on the same page, call reset_jobpost_loop() between them:

<?php
// First loop: active jobs
if (have_jobposts()):
while (have_jobposts()): the_jobpost();
the_jobpost('title');
endwhile;
endif;
// Reset before starting a new loop
reset_jobpost_loop();
// Second loop: expired jobs
if (have_expired_jobposts()):
while (have_expired_jobposts()): the_jobpost();
the_jobpost('title');
endwhile;
endif;
?>
<?php
// Total number of job posts
$total = get_jobpost_count(false);
// Number of jobs matching current filters
$filtered = get_jobpost_count(); // defaults to true
echo "$total jobs available. Showing: $filtered";
?>

Some jobs may have multiple positions. Use get_jobpost_position_count() to get the total number of open positions:

<?php
$positions_total = get_jobpost_position_count(false);
$positions_filtered = get_jobpost_position_count();
echo "$positions_total positions available. Showing: $positions_filtered";
?>