//jobs post short code reg
函数 diwp_create_shortcode_jobs_post_type(){
$args = array(
'post_type' => 'job',
'posts_per_page' => '10',
'publish_status' => 'published',
);
$query = new WP_Query($args);
if($query->have_posts()) :
while($query->have_posts()) :
$query->the_post() ;
$result .= '<div class="movie-item">';
$result .= '<div class="movie-poster">' . get_the_post_thumbnail() . '</div>';
$result .= '<div class="movie-name">' . '<a href="'.get_permalink().'">'.get_the_title().'</a>'. '</div>';
$result .= '<div class="movie-location">'.'<p>Location: </P>' . get_post_meta('get_the_id()','jobs_locations','true'). '</div>';
$result .= '<div class="movie-desc">' . get_the_excerpt(). '</div>';
$result .= '</div>';
endwhile;
wp_reset_postdata();
endif;
return $result;
}
add_shortcode('jobs-list', 'diwp_create_shortcode_jobs_post_type');
//CMB2 需要注册
require_once('cmb2/init.php');
//职位发布额外的字段注册
函数jobs_extra_fild(){
/**
* Initiate the metabox
*/
$cmb = new_cmb2_box( array(
'id' => 'jobs_metabox',
'title' => 'Jobs Extra Fields',
'object_types' => array( 'job', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
) );
// Regular text field
$cmb->add_field( array(
'name' => __( 'Jobs Location', 'cmb2' ),
'desc' => __( 'type your jobs location', 'cmb2' ),
'id' => 'jobs_locations',
'type' => 'text',
'show_on_cb' => 'cmb2_hide_if_no_cats',
) );
} add_action('cmb2_admin_init', 'jobs_extra_fild');