Hello again guys, Can someone tell me if is possible to order this dropdown by name instead of id? My code: <select name="mr_freeGalleryModel" id="mr_freeGalleryModel"> <option value="">Select</option> <?php //$mr_ModelId =get_post_meta($mrpostParent,"mr_freeGalleryModel",true); $args = array('post_type' => 'model', 'post_status' => 'publish', 'posts_per_page' => -1); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $mdoel_id = get_the_ID(); echo '<option value="'.$mdoel_id.'">'.get_the_title().'</option>'; endwhile; } wp_reset_query(); ?> </select> PHP: I need to order by post_title... Thank you!!
Yup, you just add more arguments. $args = array( 'orderby' => 'something', 'order' => 'DESC', ); Code (markup): BTW, I suggest reading up on the WordPress codex. You'll find all the properties of functions and classes there. Also, you have a typo in the code you posted, mdoel instead of model.
Thank you once again my friend I changed: $args = array('post_type' => 'model', 'post_status' => 'publish', 'posts_per_page' => -1); PHP: With: $args = array('post_type' => 'model', 'post_status' => 'publish', 'orderby' => 'post_title', 'order' => 'ASC', 'posts_per_page' => -1); PHP: Is now working perfectly thanks to you
@emily008 seriously? Are you dumb, or just wanting to up your post count? He's using WordPress. WordPress has built in functions for sorting this on the database layer, which is more efficient.