Viewing 3 reply threads
  • Author
    Posts
    • #2089

      Hello 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!

    • #2092
      Steve
      Keymaster

      @cegodaiget_posts is probably a better way to do this. I modified this tutorial to work with get_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.

    • #2096

      @Steve –

      its working now! thank you very much! i <3 piklist 😀

    • #2098
      Steve
      Keymaster

      Great! Closing Ticket.

Viewing 3 reply threads
  • The topic ‘dynamic select’ is closed to new replies.