Support » Plugin: WP Job Manager » Adding custom fields to front end form

  • Resolved georgew0304

    (@georgew0304)


    Hi,

    I’m attempting to add custom fields to job entries (such as Salary) for users of the website. I’ve managed to make it work on the backend wp-admin side, but not for the front end.

    With the backend, I’ve added an array for salary on class-wp-job-manager-writepanels.php, I tried the same for class-wp-job-manager-form-submit-job.php. I’m able to get it to add a meta key of _job_salary but the only time I can get it to give me a meta value is when adding entries from the back end.

    I’ve noticed someone else has come across this same problem here, but I still couldn’t work it out using that information.

    I’ve gone through your GitHub and looked through resources available but nothing. The only thing that seemed like a possibility is copying files from /template into my theme directory. If this is what I need to do, what files do I need to edit, and where do I need to make these edits.

    My PHP isn’t the greatest, but I have a fair bit of knowledge on it.

    Thanks.

    http://wordpress.org/plugins/wp-job-manager/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter georgew0304

    (@georgew0304)

    Alright, I’ve managed to get it to show up in the database with a meta key and meta value. I’m working on getting it to show up on the job listing now.

    Thread Starter georgew0304

    (@georgew0304)

    Ah, I have fixed it. It’s a case of adding the function to wp-job-manager-template.php.

    Hey @georgew0304, can you let me know how you did this? I’d like to add a custom field to display Application Deadline. My theme makes it easy to add the name and value on the backend. Just not sure how to do it on the front end.

    Thanks.
    http://wordpress.org/plugins/wp-job-manager/

    Thread Starter georgew0304

    (@georgew0304)

    Right, the first field you need to edit is
    includes/forms/class-wp-job-manager-form-submit-job.php

    Around line 100 you need to add an array similar to the following (Use the other arrays on the file to give you an idea)

    'application_deadline' => array(
    					'label'       => __( 'Application Deadline', 'job_manager' ),
    					'type'        => 'text',
    					'required'    => true,
    					'placeholder' => '',
    					'priority'    => 7
    				),

    Make sure you have a different priority to the others.

    Then around line 435 you need to add a line to put the form input into the database.

    Add something like this:
    update_post_meta( self::$job_id, '_application_deadline', $values['job']['application_deadline'] );

    That should handle the adding the entry to the database side of things.

    Now to add the function to get the element from the database.

    Open up the file wp-job-manager-template.php

    You can add this function to the bottom of the file:

    /**
     * Display or retrieve the current application deadline with optional content.
     *
     * @access public
     * @param mixed $id (default: null)
     * @return void
     */
    function the_application_deadline( $before = '', $after = '', $echo = true, $post = null ) {
    	$application_deadline = get_the_application_deadline( $post );
    
    	if ( strlen( $application_deadline ) == 0 )
    		return;
    
    	$application_deadline = esc_attr( strip_tags( $application_deadline ) );
    
    	if ( $echo )
    		echo $application_deadline;
    	else
    		return $application_deadline;
    }
    
    /**
     * get_the_application_deadline function.
     *
     * @access public
     * @param int $post (default: 0)
     * @return void
     */
    function get_the_application_deadline( $post = null ) {
    	$post = get_post( $post );
    	if ( $post->post_type !== 'job_listing' )
    		return;
    
    	$application_deadline = $post->_application_deadline;
    
    	if ( strlen( $application_deadline ) == 0 )
    		return;
    
    	if ( strpos( $application_deadline, '' ) === 0 )
    		$application_deadline = substr( $application_deadline, 1 );
    
    	return apply_filters( 'the_application_deadline', $application_deadline, $post );
    }

    Now you should just be able to add <?php the_application_deadline(); ?> to bring up the application deadline.

    Just an advisory, I’m not a professional developer. You should look over my code, as I’ve mainly looked over current code and replicated it with minor changes.

    Hi @georgew0304

    I followed your steps above but I’m having trouble getting any inputted date to stick, as though it is not going into the database – is there any step I may have missed out?

    Thanks

    @ritchie Badland: If you require assistance then, as per the Forum Welcome, please post your own topic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding custom fields to front end form’ is closed to new replies.