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.
Basic Loop
Section titled “Basic Loop”<?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;?>Full Example
Section titled “Full Example”<?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; ?>Limiting the Number of Jobs
Section titled “Limiting the Number of Jobs”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; ?>Pagination with Offset
Section titled “Pagination with Offset”Use the second parameter for offset:
<?php// Skip the first 10, show the next 10if (have_jobposts(10, 10)): while (have_jobposts(10, 10)): the_jobpost(); the_jobpost('title'); endwhile;endif;?>Multiple Loops
Section titled “Multiple Loops”When showing multiple feeds on the same page, call reset_jobpost_loop() between them:
<?php// First loop: active jobsif (have_jobposts()): while (have_jobposts()): the_jobpost(); the_jobpost('title'); endwhile;endif;
// Reset before starting a new loopreset_jobpost_loop();
// Second loop: expired jobsif (have_expired_jobposts()): while (have_expired_jobposts()): the_jobpost(); the_jobpost('title'); endwhile;endif;?>Job Count Functions
Section titled “Job Count Functions”<?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";?>Position Count
Section titled “Position Count”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";?>