• Hi there,

    I’m using a plugin called WP Job Manager to let users post jobs to a website. There’s quite good documention how to edit the “Job Submission Form” @ https://github.com/mikejolley/WP-Job-Manager/wiki.

    In the functions i’ve tested it by adding a salary field: https://github.com/mikejolley/WP-Job-Manager/wiki/Editing-Job-Submission-Fields

    That all goes well, but I’m wondering how I could make that custom field show up in the “Job Listings” I know that the function has to be added somehow in the “content-job_listing.php somehow.

    This is my functions.php

    add_filter( 'submit_job_form_fields', 'frontend_add_salary_field' );
    
    function frontend_add_salary_field( $fields ) {
        $fields['job']['job_salary'] = array(
            'label'       => __( 'Salary', 'job_manager' ),
            'type'        => 'text',
            'required'    => true,
            'placeholder' => '',
            'priority'    => 7
        );
        return $fields;
    }
    
    add_action( 'job_manager_update_job_data', 'frontend_add_salary_field_save', 10, 2 );
    
    function frontend_add_salary_field_save( $job_id, $values ) {
        update_post_meta( $job_id, '_job_salary', $values['job']['job_salary'] );
    }
    
    add_filter( 'job_manager_job_listing_data_fields', 'admin_add_salary_field' );
    
    function admin_add_salary_field( $fields ) {
        $fields['_job_salary'] = array(
            'label'       => __( 'Salary', 'job_manager' ),
            'type'        => 'text',
            'placeholder' => '',
            'description' => ''
        );
        return $fields;
    }

    And that function should be posted here:

    <li <?php job_listing_class(); ?>>
    	<a href="<?php the_job_permalink(); ?>">
    		<?php the_company_logo(); ?>
    		<div class="position">
    			<h3><?php the_title(); ?></h3>
    			<div class="company">
    				<?php the_company_name( '<strong>', '</strong> ' ); ?>
    				<?php the_company_tagline( '<span class="tagline">', '</span>' ); ?>
    			</div>
    		</div>
    		<div class="location">
    			<?php the_job_location( false ); ?>
    		</div>
    		<ul class="meta">
    			<li class="job-type <?php echo get_the_job_type() ? sanitize_title( get_the_job_type()->slug ) : ''; ?>"><?php the_job_type(); ?></li>
    			<li class="date"><date><?php printf( __( 'Posted %s ago', 'job_manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) ); ?></date></li>
    		</ul>
    	</a>
    </li>

    Thanks in advance 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • Any luck figuring this out?

    I know here on github they give an example for adding a company morale field. Editing it to whatever you’d like is simple enough.

    They even provide instruction to get it to the frontend. Unfortunately, it is a bit over my head.

    Did you get it to work?

    lmartin717

    (@lmartin717)

    I just figured this out today. Try going to wp-job-manager-template.php and add the 2 following functions. Just replace “jobOrderNumber” with “salary” or the name of your custom field.

    function the_jobOrderNumber( $before = '', $after = '', $echo = true, $post = null ) {
    	$jobOrderNumber = get_the_jobOrderNumber( $post );
    
    	if ( strlen( $jobOrderNumber ) == 0 )
    		return;
    
    	$jobOrderNumber = esc_attr( strip_tags( $jobOrderNumber ) );
    	$jobOrderNumber = $before . $jobOrderNumber . $after;
    
    	if ( $echo )
    		echo " ($jobOrderNumber)";
    	else
    		return $jobOrderNumber;
    }
    
    /**
     * get_the_jobOrderNumber function.
     *
     * @access public
     * @param int $post (default: null)
     * @return void
     */
    function get_the_jobOrderNumber( $post = null ) {
    	$post = get_post( $post );
    	if ( $post->post_type !== 'job_listing' )
    		return;
    
    	return apply_filters( 'the_job_OrderNumber', $post->_job_jobOrderNumber, $post );
    }

    Now in content-job-listing.php, you can use your new the_jobOrderNumber(); function, such as:

    <li <?php job_listing_class(); ?>>
    	<a href="<?php the_job_permalink(); ?>">
    		<?php the_company_logo(); ?>
    		<div class="position">
    			<h3><?php the_title();
    				if (is_user_logged_in()) {
    					the_jobOrderNumber();
    				}
    			?>
    			</h3>
    			<div class="company">
    				<?php the_company_name( '<strong>', '</strong> ' ); ?>
    				<?php the_company_tagline( '<span class="tagline">', '</span>' ); ?>
    			</div>
    		</div>
    		<div class="location">
    			<?php the_job_location( false ); ?>
    		</div>
    		<ul class="meta">
    			<li class="job-type <?php echo get_the_job_type() ? sanitize_title( get_the_job_type()->slug ) : ''; ?>"><?php the_job_type(); ?></li>
    			<li class="date"><date><?php echo human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'job_manager' ); ?></date></li>
    		</ul>
    	</a>
    </li>

    Hope this helps. Let me know how it works out.

    samirdiwan

    (@samirdiwan)

    havent been able to get this to work. Just so I’m on the same page as you, job listing is when you search for jobs and are returned a list, or an individual job listing?

    lmartin717

    (@lmartin717)

    I put mine in the job listings, but if you write those 2 functions in wp-job-manager-template.php, you should be able to call “the_jobOrderNumber();” (or “the_salary();” or whatever your custom field is) on any front-end page.

    Note that this is different than if you want the new field to show up in the job listings on the admin back-end. If you’re looking to put it on the page that has this at the end of the URL:
    wp-admin/edit.php?post_type=job_listing

    ..let me know, because that is different code entirely. I just figured it out yesterday so I can post that too if that’s what you’re looking for.

    EedAbba

    (@eedabba)

    Hi Imartin I would be curious to see the additional code you have for the backend if you didn’t mind sharing.

    EedAbba

    (@eedabba)

    I am going to add something off topic. I apologize, I am not sure where to ask it and at the very least this is a group of people trying to bend the applications of job manager. In my particular case I am using it with Jobify.

    Any initial thoughts or areas to turn to have the jobs created be posted as products (woo commerce). The end goal to have the posting be purchasable. I know this is a broad stroke.

    lmartin717

    (@lmartin717)

    Sure – sorry for the delay. Here are some reference links:

    http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types
    and
    http://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column

    And the sample code I used (you can replace _job_jobOrderNumber with whatever your custom field is). Note that in order for this to work, you will still need to add the field (https://github.com/mikejolley/WP-Job-Manager/wiki/Editing-Job-Submission-Fields) before you reference it like it is below. I added some customization in my function because I wanted to switch the order of the columns and remove some existing columns. The first link above (justintadlock) is a really good reference for customization options. Let me know if you have any questions:

    add_filter('manage_edit-job_listing_columns' , 'add_job_listing_columns');
    add_action( 'manage_job_listing_posts_custom_column' , 'custom_columns', 10, 2 );
    
    function add_job_listing_columns($columns) {
    	$new = array();
      	foreach($columns as $key => $title) {
        		if ($key=='company') // Put the Job Order Number column before the Company column
          			$new['_job_jobOrderNumber'] = 'Job Order Number';
    		if ($key !== 'filled' && $key!== 'job_expires')  // Remove Filled and Expires columns
        			$new[$key] = $title;
      	}
      	return $new;
    }
    
    function custom_columns( $column, $post_id ) {
        switch ( $column ) {
    	case '_job_jobOrderNumber' :
    		$orderNumber = get_post_meta( $post_id, '_job_jobOrderNumber', false);
    		echo __( $orderNumber[0] );
    		break;
        }
    }

    this is a bit off topic as well, but it seems like this might be a good place to ask. has anyone figured out a good way to add other options besides “job” or “company” to the listings without messing up the code for future updates? I’m sure i could completely modify the code, but eve then I’m sure I’d break it with my limited php skills. ultimately I would love to have the word “property” added along with those two, but worse case scenario i couls swap “company” for “property.”

    Any advice?

    Really appreciate if anyone could help the solve the following problem.

    I am looking for a way to add Animated Collapsible DIV to some of the fields.
    DEMO video
    However, the function requests a individual class name. Can anyone tell me how to give a particular customer field with a new DIV class name? And where should I put the CSS code in order to get the effect working?

    I am using wordpress 3.9.1 + Jobify Theme + WP Job Manager 1.13.0 + Custom fields for WP Job Manager 1.0

    Consultation fee can be provided.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: WP Job Manager] Custom fields in job listing’ is closed to new replies.