<?php

if(!function_exists('mascot_core_educacion_cpt_sc_vacancies_vc_map_modifier')) {
	/**
	 * Shortcodes vc_map modifier
	 */
	function mascot_core_educacion_cpt_sc_vacancies_vc_map_modifier( $shortcode_base ) {
		//vc_remove_param( $shortcode_base, "display_type" );
		//vc_add_param( $shortcode_base, $attributes );
		//vc_add_params( $shortcode_base, $attributes );
	}
}



if(!function_exists('mascot_core_educacion_cpt_sc_vacancies_render')) {
	/**
	 * Renders shortcodes HTML
	 */
	function mascot_core_educacion_cpt_sc_vacancies_render( $attr, $content = null, $class_instance ) {

		$new_cpt_class = $class_instance;
		$args = array(
			'custom_css_class' => '',
			'selected_category' => '',
			'order_by' => 'date',
			'order' => 'DESC',
		);
		$params = shortcode_atts($args, $attr);

		//query args
		$args = array(
			'post_type' => $new_cpt_class->ptKey,
			'orderby' => $params['order_by'],
			'order' => $params['order'],
			'posts_per_page' => -1,
		);

		//if category selected
		if( ! empty( $params['selected_category'] ) ) {
			$args['tax_query'] = array(
				array(
					'taxonomy' => $new_cpt_class->ptTaxKey,
					'field'	=> 'slug',
					'terms'	=> explode(',', $params['selected_category']),
				)
			);
		}

		$the_query = new \WP_Query( $args );
		$params['the_query'] = $the_query;

		//classes
		$classes = array();
		$classes[] = $params['custom_css_class'];
		$params['classes'] = $classes;

		//Produce HTML version by using the parameters (filename, variation, folder name, parameters, shortcode_ob_start)
		$html = educacion_mascot_get_cpt_template_part( 'vacancies', null, 'vacancies/shortcodes/tpl', $params, true );
		
		return $html;
	}
}