Viewing 3 reply threads
  • Author
    Posts
    • #5007
      bicho44
      Member

      Hi:

      I made a widget to make a search by taxonomies and i wanna use the onchange, so when the client try to search by one of the values the page, jump to that Taxonomy/Category.

      But i dont know how to make this happend or if ther is a piklist way to do it.

      My Front page Widget code

      <?php
      /*  
      Title: Buscar por Categoría
      Class: categoria
      Width: 300
      */
      
      echo $before_widget;
      
      echo $before_title;
      
      echo $settings['buscar_title'];
      
      echo $after_title;
      
      $buscadores = $settings['buscarxcategorias'];
      
      foreach ($buscadores as $id => $value)
      {
          //echo $value;
      
          /* Obtengo la data de cada categoría */
          $categoria = get_taxonomy($value);
      
          if ($categoria) {
      
              //piklist::pre($categoria);
      
              /*
               * Para saber el Nombre en Singular
               * $categoria->labels->name
               */
      
              piklist('field', array(
                      'type' => 'select'
                  , 'scope' => 'taxonomy'
                  , 'field' => $value
                  , 'label' => $categoria->labels->name.' de Productos'
                  , 'columns' => '9'
                  , 'choices' =>
                          array('' => 'Seleccione para buscar') +
                          piklist(
                              get_terms($value, array('hide_empty' => false))
                              , array(
                                  'slug'
                                  , 'name'
                              )
                          )
                  )
              );
          }
      }
      
      ?>
      
      <?php
      echo $after_widget;

      If anyone have an idea, i really apreciate 😀

    • #5012
      Steve
      Keymaster

      @bicho44– The attributes parameter allows you to pass field attributes:

      piklist('field', array(
        'type' => 'select'
        ,'scope' => 'taxonomy'
        ,'field' => $value
        ,'label' => $categoria->labels->name.' de Productos'
        ,'columns' => '9'
        ,'choices' => array('' => 'Seleccione para buscar') +
          piklist(
            get_terms($value, array('hide_empty' => false))
            , array(
              'slug'
              ,'name'
            )
          )
        )
        ,'attributes' => array(
          'onchange' => 'myFunction()'
        )
      );
      
    • #5014
      bicho44
      Member

      Thaks, amazing

    • #5015
      Steve
      Keymaster

      Glad you like it! 😉

      Closing ticket.

Viewing 3 reply threads
  • The topic ‘Dropdown with onchage’ is closed to new replies.