Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timiwahalahti/b5d0439539b2fe59e9f7be69fbf932c4 to your computer and use it in GitHub Desktop.
Save timiwahalahti/b5d0439539b2fe59e9f7be69fbf932c4 to your computer and use it in GitHub Desktop.
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