Created
April 23, 2020 11:14
Star
You must be signed in to star a gist
MAS WPJMC - Get the Company Name From Company ID Linked in Job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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