I followed this tutorial to add custom fields:

I followed this tutorial to add custom fields:

https://premium.wpmudev.org/forums/topic/is-it-possible-to-add-additional-fields-to-the-jobs-create-form

I also used it to display the custom fields on the job page. I want to add some of this data to the snippet on the job listing page.

Where it says the job title and the meta info, I want to add my custom field info in the meta or the title.

EDIT: I added my own hook in main.php for Job Archives. I then use add_action('hook_name', 'function') in the plugin.

Just like the tutorial I use:

<?php echo $model->model_name ?>
in this case I am trying to display the job_location and hiring_entity fields form the custom job fields I ask for. I am having issues because they are not showing.

  • Michael Bissett

    Hey @Albert, hope you're doing well today! :slight_smile:

    Could you share the code that you're using presently for the handling of these custom fields? You're using CustomPress to create these custom fields, correct?

    And could you enable Support Access to your site, just in case I need to check how you've set things up there?

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Please advise,
    Michael

  • Albert

    Support access granted.

    Not using custom press, just using a plugin

    The code:

    <?php  
    
    /*
    Plugin Name: AADI Job Custom Fields
    Author:
    Version: 1.0
    */
    
    add_filter( 'je_job_additions_field', 'job_add_extra_field' );
    
    function job_add_extra_field( $fields ) {
    	$fields = array_merge( $fields, array(
    		'hiring_entity',
    		'job_location'
    	) );
    
    	return $fields;
    }
    
    add_filter('je_job_validation_rules', 'job_add_location_validation_rule');
    function job_add_location_validation_rule( $rules ) {
    	$rules = array_merge( $rules, array(
    		'job_location' => 'required',
    		'hiring_entity'=> 'required'
    	) );
    
    	return $rules;
    }
    
    add_filter( 'je_job_field_name', 'job_extra_field_name' );
    function job_extra_field_name( $names ) {
    	$names = array_merge( $names, array(
    		'hiring_entity'    	 => "Hiring Entity",
    		'job_location'			 => "Job Location"
    	) );
    
    	return $names;
    }
    
    add_filter( 'je_job_relations', 'job_extra_relations' );
    function job_extra_relations( $relations ) {
    	$relations = array_merge( $relations, array(
    		array(
    			'type' => 'meta',
    			'key'  => 'hiring_entity',
    			'map'  => 'hiring_entity'
    		),
    		array(
    			'type' => 'meta',
    			'key'  => 'job_location',
    			'map'  => 'job_location'
    		),
    	) );
    
    	return $relations;
    }
    
    add_action( 'je_after_job_title_field', 'add_extra_form_fields', 10, 2 );
    function add_extra_form_fields( JE_Job_Model $model, IG_Active_Form $form ) {
    	if ( is_admin() ) {
    		?>
    <!--	hiring entity-->
    		<div class="form-group <?php echo $model->has_error( "hiring_entity" ) ? "has-error" : null ?>">
    			<?php $form->label( "hiring_entity", array(
    				"text"       => "Hiring Entity",
    				"attributes" => array( "class" => "col-lg-3 control-label" )
    			) ) ?>
    			<div class="col-lg-9">
    				<?php $form->text( "hiring_entity", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
    				<span class="help-block m-b-none error-job_title"><?php $form->error( "hiring_entity" ) ?></span>
    			</div>
    			<div class="clearfix"></div>
    		</div>
    <!--job location		-->
    		<div class="form-group <?php echo $model->has_error( "job_location" ) ? "has-error" : null ?>">
    			<?php $form->label( "job_location", array(
    				"text"       => "Job Location",
    				"attributes" => array( "class" => "col-lg-3 control-label" )
    			) ) ?>
    			<div class="col-lg-9">
    				<?php $form->text( "job_location", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
    				<span class="help-block m-b-none error-job_title"><?php $form->error( "job_location" ) ?></span>
    			</div>
    			<div class="clearfix"></div>
    		</div>
    
    	<?php
    	} else {
    		?>
    		<div class="form-group <?php echo $model->has_error( "hiring_entity" ) ? "has-error" : null ?>">
    			<?php $form->label( "hiring_entity", array(
    				"text"       => "Hiring Entity",
    				"attributes" => array( "class" => "col-lg-3 control-label" )
    			) ) ?>
    			<div class="col-lg-9">
    				<?php $form->text( "hiring_entity", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
    				<span class="help-block m-b-none error-job_title"><?php $form->error( "hiring_entity" ) ?></span>
    			</div>
    			<div class="clearfix"></div>
    		</div>
    
    		<div class="form-group <?php echo $model->has_error( "job_location" ) ? "has-error" : null ?>">
    			<?php $form->label( "job_location", array(
    				"text"       => "Job Location",
    				"attributes" => array( "class" => "col-lg-3 control-label" )
    			) ) ?>
    			<div class="col-lg-9">
    				<?php $form->text( "job_location", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
    				<span class="help-block m-b-none error-job_title"><?php $form->error( "job_location" ) ?></span>
    			</div>
    			<div class="clearfix"></div>
    		</div>
    
    		<?php
    	}
    }
    
    add_action( 'je_job_single_before_attachments', 'job_display_custom_fields' );
    function job_display_custom_fields( $model ) {
    	if ( $model->hiring_entity ) {
    		?>
    		<div class="row">
    			<div class="col-md-12">
    				<?php echo "Hiring Entity:" ?>
    				<?php echo $model->hiring_entity ?>
    			</div>
    		</div>
    	<?php
    	}
    
    	if ( $model->job_location ) {
    		?>
    		<div class="row">
    			<div class="col-md-12">
    				<?php echo "Job Location:" ?>
    				<?php echo $model->job_location ?>
    			</div>
    		</div>
    	<?php
    	}}
    
    add_action('jbp_job_listing_inside', 'job_display_custom_meta');
    function job_display_custom_meta($model) {
    		if ($model->hiring_entity){
    			echo $model->hiring_entity;
    		}
    	}
    ?>

    I added a custom hook in main.php called jbp_job_listing_inside

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.