Created
April 11, 2017 07:11
-
-
Save timiwahalahti/b5d0439539b2fe59e9f7be69fbf932c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode( 'wplfdynamicselect', 'wpfi_wplf_dynamic_select' ); | |
function wpfi_wplf_dynamic_select( $atts ) { | |
$the_query = new WP_Query( array( | |
'post_type' => 'CPT', | |
'post_status' => 'publish', | |
'posts_per_page' => 100, | |
'order' => 'DESC', | |
'orderby' => 'title', | |
'no_found_rows' => true, | |
'update_post_meta_cache' => false, | |
'update_post_term_cache' => false | |
) ); | |
if( $the_query->have_posts() ): | |
$return = '<select name="company">'; | |
while( $the_query->have_posts() ): | |
$the_query->the_post(); | |
$return .= '<option value="'.get_the_id().'">'.get_the_title().'</option>'; | |
endwhile; | |
$return .= '</select>'; | |
endif; | |
wp_reset_postdata(); | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment