<?php
function alter_title($title)
{
    if(is_singular(['matador-job-listings', 'job'])){
        $title = get_the_title();
    }
    return $title;
}
add_filter('wpex_title', 'alter_title', 20);

// remove breadcrumbs
add_action('template_redirect', function(){
    if(is_singular('job')){
        remove_action( 'wpex_hook_page_header_inner', 'wpex_display_breadcrumbs', 10 );
    }
});

function my_remove_author_subheading($subheading)
{
    if(is_singular(['matador-job-listings', 'job'])){
        $id = get_the_ID();
        $state = get_post_meta( $id, 'state', true ) ? get_post_meta($id, 'state', true) : '';
        $jobnumber = get_post_meta($id, 'job_id', true) ? get_post_meta($id, 'job_id', true) : '';

        $webcategory = wp_get_post_terms($id, 'job-category');
        $category = array_map(function($obj){
            return $obj->name;
        }, $webcategory);

        $subheading = $state;
        if($jobnumber){
            if ($state) $subheading .= ' | ';
            $subheading .= 'Job Number ' . $jobnumber;
        }
        if(is_array($category)){
            if ($jobnumber) $subheading .= ' | ';
            $subheading .= implode(', ', $category);
        }
    }
    // Return the subheading
    return $subheading;
}
add_filter('wpex_post_subheading', 'my_remove_author_subheading');
