<?php

/**
 * Registers 'vacancies' post type 
 *
 * This function registers the 'vacancies' posts
 * type which is used for the vacancies posts.
 *
 * @function vacancies_post_type()
 *
 * @uses register_post_type()
 *
 * @param N/A
 *
 * @return N/A
 *
 * @since 1.3.9 
 *
 */
function vacancies_post_type() {
	
	$labels = array(
		'name' 				 => _x( 'Vacancies', 'post type general name' ),
		'singular_name' 	 => _x( 'Vacancy', 'post type singular name' ),
		'menu_name' 		 => __( 'Vacancies' ),
		'add_new' 			 => _x( 'Add New', 'team item' ),
		'add_new_item' 		 => __( 'Add New Vacancy' ),
		'edit_item' 		 => __( 'Edit Vacancy' ),
		'new_item' 			 => __( 'New Vacancy' ),
		'view_item' 		 => __( 'View Vacancy' ),
		'search_items' 		 => __( 'Search Vacancies' ),
		'not_found' 		 => __( 'No Vacancies Found' ),
		'not_found_in_trash' => __( 'No Vacancies Found in Trash' ),
		'parent_item_colon'  => '',
	);
	register_post_type( 'vacancies-posts', array(
		'labels' 	=> $labels,
		'public' 	=> true,
		'menu_icon' => 'dashicons-businessman',
		'supports'  => array( 'title', 'editor' ),
		'show_in_rest' => true,
	) );
}
add_action( 'init', 'vacancies_post_type', 0 );



/**
 * Returns 'vacancies-posts' post type 
 *
 * This function returns the 'vacancies-posts'
 * posts type which is used for the vacancies
 * posts. The posts are returned using the
 * vacancies template located in the
 * WordPress Theme.
 *
 * @function add_vacancies()
 *
 * @uses WP_Query::the_post(), get_template_part()
 *
 * @param N/A
 *
 * @return (string) The vacancies-posts' posts
 *
 * @since 1.0.0 
 *
 */
function add_vacancies( $var ) {
	
    $query = new WP_Query( array(
		'post_type' 	 => 'vacancies-posts',
		'posts_per_page' => -1,
    ) );
	$string = '';
	
	if ( $query->have_posts() ) {
		
		while ( $query->have_posts() ){
			
			$query->the_post();
			
			ob_start();
			
			get_template_part( 'templates/vacancies' );
			
			$string .= ob_get_clean();
		}
	}
	wp_reset_postdata();
	return $string;
}
add_shortcode( 'vacancies', 'add_vacancies' );