Post_Dropdown_Custom_Control

Class to create a custom post control.

Defined (1)

The class is defined in the following location(s).

/lib/customizer/includes/post-dropdown-custom-control.php  
  1. class Post_Dropdown_Custom_Control extends WP_Customize_Control { 
  2. private $posts = false; 
  3.  
  4. public function __construct( $manager, $id, $args = array(), $options = array() ) { 
  5. $postargs = wp_parse_args( $options, array( 'numberposts' => '-1', 'post_type' => 'page' ) ); 
  6. $this->posts = get_posts( $postargs ); 
  7.  
  8. parent::__construct( $manager, $id, $args ); 
  9.  
  10. /** 
  11. * Render the content on the theme customizer page 
  12. */ 
  13. public function render_content() { 
  14. if ( ! empty( $this->posts ) ) { 
  15. ?> 
  16. <label> 
  17. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> 
  18. <span class="description customize-control-description"><?php echo esc_attr( $this->description ); ?></span> 
  19. <select name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>"> 
  20. <?php 
  21. foreach ( $this->posts as $post ) { 
  22. printf('<option value="%s" %s>%s</option>', $post->ID, selected( $this->value(), $post->ID, false), $post->post_title ); 
  23. ?> 
  24. </select> 
  25. </label> 
  26. <?php