<?php

class Chic_Lifestyle_Dropdown_Posttype extends WP_Customize_Control {

	public $posttype = '';


	public function __construct( $manager, $id, $args = array() ) {

	    $chic_lifestyle_posttype = 'trip';
	    if ( isset( $args['posttype'] ) ) {
	      $posttype_exist = post_type_exists( esc_attr( $args['posttype'] ) );
	      if ( true === $posttype_exist ) {
	        $our_taxonomy = esc_attr( $args['posttype'] );
	      }
	    }
	    $this->posttype = esc_attr( $chic_lifestyle_posttype );

	    parent::__construct( $manager, $id, $args );
	 }

	protected function render_content() {
		
		$posttype = $this->posttype;
		$args = array(
			'post_type' => $posttype,
			'posts_per_page' => '-1'
		);
		$all_posts = get_posts( $args );
	?>

		<label>
	      <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
	         <select <?php echo $this->link(); ?>>
	            <?php
	              printf('<option value="%s" %s>%s</option>', '', selected($this->value(), '', false),__( 'Select', 'chic-lifestyle') );
	             ?>
	            <?php if ( ! empty( $all_posts ) ): ?>
	              <?php foreach ( $all_posts as $all_post ): ?>
	                <?php 
	                  printf('<option value="%s" %s>%s</option>', $all_post->post_name, selected($this->value(), $all_post->post_name, false), $all_post->post_title );
	                 ?>
	              <?php endforeach; ?>
	           <?php endif; ?>
	         </select>

	    </label>
	    <?php

	}
}