How to hide expired jobs from the jobs board

Hi,

1. I want to hide expired jobs from the jobs board automatically.

Currently all jobs continue to display on the jobs board indefinitely. I would like the jobs board to only display live jobs.

My current jobs board is here: http://twid.simplecsr.com/demo/

(Support access is open on this site)

Thanks
Chris

  • Patrick

    Hi there @chris

    I hope you're well today!

    I just checked on my own test site to see if there are any specific CSS classes we can use to hide expired jobs. But alas, there are none; just the text "This job expired".

    It can possibly be done via a bit of jQuery wizardry by checking for the presence of that text and then hiding the div container if found. But I'm not quite sure how to do that, so I've asked for some input from our 2nd-level support team. One of them should be by soon to lend a hand.

    In the meantime, I've also notified the plugin developer so we can perhaps get an expired class added in a future update of the plugin.

  • Patrick

    Hi again @chris

    Indeed, jQuery can get the job done. I just tested on my own site with the following snippet added to my theme's header.php file just before the closing /head tag:

    <script type="text/javascript">
    jQuery(function($) {
    $( ".jbp_job_item:contains('This job expired')" ).css({ "display": "none", "visibility": "hidden" }) ;
    });
    </script>

    However, that does not affect the pagination as the plugin still thinks there are more jobs to display. See an example on my test site here:
    http://jobs-experts.pcwriter.net/job/

  • chris

    Hi Patrick,

    I tested this out and get the same results on my theme (displaying pagination)
    Also, with this method you can see the jobs load initially before being hidden.

    I have already had to edit the main.php file in /jobs-plus/app/views/job-archive

    Could this code be changed to change the behaviour of expired jobs - they are identified as the text is being changed if expired.

    The code from the main.php file is added below:

    <div class="ig-container">
        <div class="hn-container">
            <div class="job-search">
    <?php dynamic_sidebar( 'my-custom-sidebar' ); ?>
            </div>
            <?php if (empty($chunks)): ?>
                <h2><?php _e('No Job Found', je()->domain); ?></h2>
            <?php else: ?>
                <div class="jbp-job-list">
                    <?php foreach ($chunks as $chunk): ?>
                        <div class="row no-margin">
                            <?php foreach ($chunk as $key => $col): ?>
                                <?php
                                $color = '';
                                if ($colors) {
                                    $color = $colors[array_rand($colors)];
                                }
                                $model = $col['item'];
                                $size = $col['class'];
    
                                setup_postdata($model->wp_post);
                                ?>
                                <div <?php echo $key == 0 ? 'style="margin-left:0"' : null ?>
                                    class="jbp_job_item <?php echo $size; ?> no-padding">
                                    <div class="jbp_job_except <?php echo $color ?>">
                                        <div class="jbp_inside">
                                            <h4>
                                                <a href="<?php echo get_permalink($model->id) ?>"><?php echo apply_filters('jbp_job_list_title', wp_trim_words($model->job_title, 10), $model->job_title) ?></a>
                                            </h4>
    <div class="author_of_this_job">By <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a></div>
    
                                            <?php if ($model->is_expired()): ?>
                                                <?php _e("This job expired", je()->domain) ?>
                                            <?php else: ?>
                                                <?php if (!isset($lite) || $lite == false): ?>
                                                    <div class="ellipsis">
                                                        <?php
                                                        $content = get_the_content();
                                                        //cal the except words count base on element width
                                                        $sub = count($chunk);
                                                        if (isset($col['text_length'])) {
                                                            $sub = $col['text_length'];
                                                        }
                                                        $content = strip_tags($content);
                                                        $charlength = 48 / $sub;
                                                        echo apply_filters('jbp_job_list_content', wp_trim_words($content, $charlength), $content, $charlength,$model);
                                                        ?>
                                                    </div>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                            <div class="jbp_job_bottom">
                                                <div class="jbp_terms">
                                                    <?php echo the_terms($model->id, 'jbp_category', __('Categories: ', je()->domain), ', ', ''); ?>
                                                </div>
                                                <div class="jbp_meta">
                                                    <div class="pull-left">
                                                        <?php _e('Due: ', je()->domain); ?><?php echo $model->get_end_date() ?>
                                                    </div>
                                                    <div class="pull-right">
                                                        <?php _e('Budget: ', je()->domain); ?>
                                                        <?php
                                                        $model->render_prices('max');
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                            <div style="clear: both"></div>
                        </div>
                    <?php endforeach; ?>
                </div>
                <?php $this->render_partial('job-archive/_paging', array(
                    'total_pages' => $total_pages
                )) ?>
            <?php endif; ?>
            <div style="clear: both"></div>
        </div>
    </div>

    Thanks
    chris

  • Sajid

    Hi @Chris

    Hope you are doing good today :slight_smile:

    I am sorry for terrible delay here.

    Go to wp-content/plugins/jobs-plus/app/views/job-archive, open up main.php file.

    Add following line of code, in main.php file:
    if ($model->is_expired()) continue;

    Right after:
    setup_postdata($model->wp_post);

    This will exclude the expired jobs.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Hoang Ngo

    Hi @chris,

    I hope you are well today and I'm sorry for the delay.

    Can you please revert the changes to plugin code, and add this code to your theme functions.php or use mu-plugins

    add_filter( 'jbp_job_search_params', 'exclude_expires_job' );
    function exclude_expires_job( $args ) {
    	$jobs = JE_Job_Model::model()->all();
    	foreach ( $jobs as $job ) {
    		if($job->is_expired()){
    			$args['post__not_in'][]=$job->id;
    		}
    	}
    
    	return $args;
    }

    This will prevent expired jobs displaying, also, fix the pagination too :slight_smile:

    Best regards,
    Hoang

  • chris

    Hi,

    Expired jobs are no longer being hidden on my sites.

    I had a new code as per https://premium.wpmudev.org/forums/topic/method-to-allow-users-to-mark-their-jobs-as

    This was suppose to contain a fix for hiding the expired jobs. I now see all expired jobs are still showing.

    The code was:

    `add_filter( 'jbp_job_search_params', 'exclude_expires_job' );
    function exclude_expires_job( $args ) {
    $jobs = JE_Job_Model::model()->all();
    foreach ( $jobs as $job ) {
    if ( $job->is_expired() ) {
    $args['post__not_in'][] = $job->id;
    }
    }

    $meta_query = array(
    array(
    'key' => 'custom_job_status',
    'value' => 'skill_1',
    'compare' => '=',
    ),
    );
    if ( ! isset( $args['meta_query'] ) ) {
    $args['meta_query'] = $meta_query;
    } else {
    $args['meta_query'] = array_merge( $args['meta_query'], $meta_query );
    }

    return $args;
    }

    Can you please check - Support access is open.

    Thanks
    chris

  • chris

    Hi Patrick and Hoang,

    I have found that the function to exclude expired jobs is directly related to whether the Advanced Search add on is active or not.

    I have tested this on a few different sites and it is always the same - disable Advanced Search and the jobs that have expired or have a custom status other than OPEN will be hidden... enable Advanced search add on and all jobs will show regardless.

    I hope this is helpful to understand the changes needed.

    Thanks
    Chris

  • Hoang Ngo

    Hi @chris,

    I hope you are well today, and I'm sorry for the delay.

    I was working for the MarketPress 3.0 project, so my response will be a little slower :slight_frown:

    Can you please try this

    add_filter( 'jbp_job_search_params', 'exclude_expires_job', 20 );
    function exclude_expires_job( $args ) {
    	$jobs = JE_Job_Model::model()->all();
    	foreach ( $jobs as $job ) {
    		if ( $job->is_expired() ) {
    			$args['post__not_in'][] = $job->id;
    		}
    	}
    
    	$meta_query = array(
    		array(
    			'key'     => 'custom_job_status',
    			'value'   => 'skill_1',
    			'compare' => '=',
    		),
    	);
    
    	if ( ! isset( $args['meta_query'] ) ) {
    		$args['meta_query'] = $meta_query;
    	} else {
    		$args['meta_query'] = array_merge( $args['meta_query'], $meta_query );
    	}
    
    	return $args;
    }

    This will put the filter priority a little bit later then the advance search. Lets see if that code works for you :slight_smile:

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.