- This topic has 3 replies, 2 voices, and was last updated 7 years, 6 months ago by
Steve.
Viewing 3 reply threads
-
AuthorPosts
-
-
July 29, 2014 at 7:17 pm #2089
Dante CervantesMemberHello i want to select one of my cpt to another post i dont want to use post-relate because i actually using it and its not working like i want, so i need select only one option, so when i do the query
$args = array( 'post_type' => 'estado', 'post_per_page' -1, 'order' => 'ASC', 'orderby' => 'title' ); $query = new WP_Query($args); $states = array(); while($query->have_posts()) : $query->the_post(); $states[get_the_ID()] = get_the_title(); endwhile; piklist('field',array( 'type' => 'select', 'columns' => 12, 'field' => 'estados', 'label' => 'Estados relacionados', 'choices' => $states ) );but when i go to edit my post and update it, the first option is selected forever, where is my error? or how can i create a dynamic select?
Thanks!
-
July 30, 2014 at 9:14 am #2092
SteveKeymaster@cegodai–
get_postsis probably a better way to do this. I modified this tutorial to work withget_posts.piklist('field',array( 'type' => 'select', 'columns' => 12, 'field' => 'estados', 'label' => 'Estados relacionados', 'choices' => piklist( get_posts(array( 'post_type' => 'estado' ,'posts_per_page' => -1 )) ,array( 'ID' ,'post_title' ) ) ) );Let me know if this works for you.
-
July 30, 2014 at 1:00 pm #2096
Dante CervantesMember@Steve –
its working now! thank you very much! i <3 piklist 😀
-
July 30, 2014 at 3:25 pm #2098
SteveKeymasterGreat! Closing Ticket.
-
-
AuthorPosts
Viewing 3 reply threads
- The topic ‘dynamic select’ is closed to new replies.