Advertisement
Guest User

select posts WCK

a guest
Jul 19th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  /* @param string $meta Meta name.   
  3.  * @param array $details Contains the details for the field.     
  4.  * @param string $value Contains input value;
  5.  * @param string $context Context where the function is used. Depending on it some actions are preformed.;
  6.  * @return string $element input element html string. */
  7.  
  8.  
  9. wp_reset_postdata();
  10. $details['options'] = array();
  11. $query = new WP_Query( array('post_type' => 'post', 'posts_per_page'=>-1));
  12. while ( $query->have_posts() ) {
  13.     $query->the_post();
  14.     $details['options'][] = get_the_title();
  15.    
  16. }
  17.  
  18. wp_reset_postdata();
  19.  
  20.  
  21. $element .= '<select multiple name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'"  id="'. $frontend_prefix . esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" class="mb-select mb-field" >';
  22.            
  23. if( !empty( $details['default-option'] ) && $details['default-option'] )
  24.     $element .= '<option value="">'. __('...Chose', 'wck') .'</option>';
  25.  
  26. if( !empty( $details['options'] ) ){
  27.  
  28.         $i = 0;
  29.         $options = '';
  30.         foreach( $details['options'] as $option ){
  31.            
  32.             if( strpos( $option, '%' ) === false ){
  33.                 $label = $option;
  34.                 if( !empty( $details['values'] ) )
  35.                     $value_attr = $details['values'][$i];
  36.                 else
  37.                     $value_attr = $option;
  38.             }
  39.             else{
  40.                 $option_parts = explode( '%', $option );
  41.                 if( !empty( $option_parts ) ){
  42.                     if( empty( $option_parts[0] ) && count( $option_parts ) == 3 ){
  43.                         $label = $option_parts[1];
  44.                         if( !empty( $details['values'] ) )
  45.                             $value_attr = $details['values'][$i];
  46.                         else
  47.                             $value_attr = $option_parts[2];
  48.                     }
  49.                 }
  50.             }
  51.                
  52.             $options .= '<option value="'. esc_attr( $value_attr ) .'"  '. selected( $value_attr, $value, false ) .' >'. esc_html( $label ) .'</option>';
  53.             $i++;
  54.         }
  55. }              
  56. $field_name = sanitize_title_with_dashes( remove_accents( $details['title'] ) );
  57. $element .= apply_filters( "wck_select_{$meta}_{$field_name}_options", $options ); 
  58. $element .= '</select>';
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement