Mapping Schema to Fields

This topic contains 9 replies, has 3 voices, and was last updated by  Will Hill 4 years, 3 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #524294

    Will Hill
    Expired Member
    Post count: 73

    So I’ve created a Jobs CPT and used the support documents to add the “JobPosting” schema type to all of the job categories. However, it doesn’t map the fields to what the schema documentation requires. For example, the Job Type field (where an employer can select part time, full time, intern, etc.)doesn’t map the employmentType schema attribute. There are around 8 of these where we have the fields that line up, but they don’t seem to automatically translate to the schema. Is there a way to manually dictate what each field should line up to for the Schema?

    #524312

    Alex Rollin
    Moderator
    Post count: 27815

    I will flag your question for the developers.

    #524389

    Kiran
    Moderator
    Post count: 7069

    Hi Will,

    Fields are dynamic and field names depends on site requirement. At the time it renders basic fields to schema.

    There is already hook available to customize schema. Please provide site link & FTP credentials so i can provide PHP snippet to render jobPosting schema.

    Regards,
    Kiran

    #524517

    Will Hill
    Expired Member
    Post count: 73
    This reply has been marked as private.
    #524561

    Alex Rollin
    Moderator
    Post count: 27815
    This reply has been marked as private.
    #524573

    Will Hill
    Expired Member
    Post count: 73
    This reply has been marked as private.
    #524596

    Kiran
    Moderator
    Post count: 7069

    Hi Will,

    Please check i have added PHP snippet to render JobPosting schema based on gd_job custom fields.

    Kiran

    #524711

    Will Hill
    Expired Member
    Post count: 73

    Kiran,

    That looks good. Could you share what snippet you used and where so I can do that on my own for future schema adjustments?

    #524749

    Kiran
    Moderator
    Post count: 7069

    Hi Will,

    I have used following PHP snippet. You can also find it on your backend > Snippets > JobPosting Schema

    
    
    /**
     * JobPosting Schema
     */
    function gd_snippet_200108_job_posting_schema( $schema, $post ) {
    	global $gd_post;
    
    	if ( ! empty( $gd_post ) && ! empty( $gd_post->post_type ) && $gd_post->post_type == 'gd_job' ) {
    		$schema['@type'] = 'JobPosting';
    
    		// datePosted
    		$schema['datePosted'] = str_replace( ' ', 'T', date_i18n( 'Y-m-d H:i:s', strtotime( $post->post_date ) ) );
    
    		// hiringOrganization
    		$hiringOrganization = array();
    		$hiringOrganization["@type"] = "Organization";
    		$hiringOrganization["name"] = ! empty( $gd_post->businessorganization_name ) ? $gd_post->businessorganization_name : 'n/a';
    		$hiringOrganization["sameAs"] = $gd_post->website;
    		$schema['hiringOrganization'] = $hiringOrganization;
    
    		// jobLocation
    		$jobLocation = array();
    		$jobLocation["@type"] = "Place";
    		//$jobLocation["name"] = $schema['name'];
    		$jobLocation["address"] = $schema['address'];
    		if ( ! empty( $schema['telephone'] ) ) {
    			$jobLocation["telephone"] = $schema['telephone'];
    		}
    		$schema['jobLocation'] = $jobLocation;
    		
    		// jobLocationType 
    		$schema['jobLocationType'] = 'TELECOMMUTE';
    
    		// title
    		$schema['title'] = $schema['name'];
    
    		// validThrough
    		if ( ! empty( $gd_post->expire_date ) && geodir_strtolower( $gd_post->expire_date ) != 'never' && $gd_post->expire_date != '0000-00-00' ) {
    			$schema['validThrough'] = str_replace( ' ', 'T', date_i18n( 'Y-m-d H:i:s', strtotime( $gd_post->expire_date ) ) );
    		} else {
    			$schema['validThrough'] = str_replace( ' ', 'T', date_i18n( 'Y-m-d H:i:s', strtotime( '+30 day' ) ) );
    		}
    
    		// baseSalary
    		$baseSalary = array();
    		$baseSalary['@type'] = "MonetaryAmount";
    		$baseSalary['currency'] = "USD";
    		$baseSalary['value'] = array(
    			"@type" => "QuantitativeValue",
    			"value" => ( ! empty( $gd_post->enter_a_wagesalary_estimate ) ? $gd_post->enter_a_wagesalary_estimate : 'n/a' ),
    			"unitText" => "YEAR"
    		);
    		$schema['baseSalary'] = $baseSalary;
    
    		// employmentType
    		$schema['employmentType'] = ! empty( $gd_post->job_type ) ? str_replace( ' ', '_', geodir_strtoupper( $gd_post->job_type ) ) : 'OTHER';
    	}
    	return $schema;
    }
    add_filter( 'geodir_details_schema', 'gd_snippet_200108_job_posting_schema', 20, 2 );

    Kiran

    #524864

    Will Hill
    Expired Member
    Post count: 73

    Kiran,

    Perfect. Thank you. I’m hoping to make some slight adjustments to the way Event schema is mapped to adjust to some of our custom fields, and with this as a template I might be able to figure it out.

Viewing 10 posts - 1 through 10 (of 10 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket