Skip to content

Instantly share code, notes, and snippets.

@yousufansa
Created April 23, 2020 11:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yousufansa/975a5aa4b831cce999b287709eaf4c71 to your computer and use it in GitHub Desktop.
MAS WPJMC - Get the Company Name From Company ID Linked in Job
<?php
/**
* Single view Company information box
*
* Hooked into single_job_listing_start priority 30
*
* This template can be overridden by copying it to yourtheme/job_manager/content-single-job_listing-company.php.
*
* @see https://wpjobmanager.com/document/template-overrides/
* @author Automattic
* @package wp-job-manager
* @category Template
* @since 1.14.0
* @version 1.32.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! get_the_company_name() ) {
return;
}
?>
<div class="company">
<?php the_company_logo(); ?>
<p class="name">
<?php if ( $website = get_the_company_website() ) : ?>
<a class="website" href="<?php echo esc_url( $website ); ?>" rel="nofollow"><?php esc_html_e( 'Website', 'wp-job-manager' ); ?></a>
<?php endif; ?>
<?php the_company_twitter(); ?>
<?php
$post = get_post();
$company_id = '';
if ( post_type_exists( 'company' ) || get_post_type( $post->ID ) == 'job_listings' ) {
$company_id = get_post_meta( $post->ID, '_company_id', true );
}
if( ! empty( $company_id ) ) {
?><a href="<?php echo get_the_permalink( $company_id ); ?>" class="company-name__link"><?php
}
the_company_name( '<strong>', '</strong>' );
if( ! empty( $company_id ) ) {
?></a><?php
}
?>
</p>
<?php the_company_tagline( '<p class="tagline">', '</p>' ); ?>
<?php the_company_video(); ?>
</div>
if( ! function_exists( 'mas_wpjmc_the_company_name' ) ) {
function mas_wpjmc_the_company_name( $company_name, $post ) {
if ( post_type_exists( 'company' ) || get_post_type( $post->ID ) == 'job_listings' ) {
$company_id = get_post_meta( $post->ID, '_company_id', true );
if( ! empty( $company_id ) ) {
$company_name = get_the_title( $company_id );
}
}
return $company_name;
}
}
add_filter( 'the_company_name', 'mas_wpjmc_the_company_name', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment