Viewing 5 reply threads
  • Author
    Posts
    • #5285
      bicho44
      Member

      Hi: Im here again :D:

      I found an almost working version of the problem, but i need just a little help with something.

      This is my code right now

      $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);
              $catname= strtolower($categoria->labels->name);
      
              //piklist::pre($categoria);
      
              /*
              * Para saber el Nombre en Singular
              * $categoria->labels->name
               *
               * El valor debe ser url/cat/slug
              */
      
              $url = esc_url( home_url( '/'));
      
              piklist('field', array(
              'type' => 'select'
              , 'scope' => 'taxonomy'
              , 'field' => $catname
              , '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' => "window.document.location.href=this.options[this.selectedIndex].value;"
                      )
                  )
      
              );
      
          }
      }

      The code almost works because i need in this part

      piklist(
                      get_terms($value, array('hide_empty' => false))
                          , array(
                              'slug'
                              , 'name'
                          )
                      )

      I have to change the slug for a full URL something like mysite.com/[taxonomy]/[slug] because thats the URL i need 😀

      The variable $catname is the taxonomy, so i only need away to construct the url

      Any ideas of how can i make it happend?

      I really thank everybody for the help.

      Regards from patagonia
      Fede

    • #5293
      Steve
      Keymaster

      Does your get_terms() code work?

    • #5295
      bicho44
      Member

      Yeah, the get_terms()works, and the slug is published, but i need a little more than the slug i need almost the full url in that place

      How can i mix thing in that array? Im trying to use piklist all the way, lol 😀

      Again Thanks in advance.

    • #5325
      Steve
      Keymaster

      You should be able to piece together the url using standard WordPress/PHP functions. You even know the taxonomy: $value.

    • #5346
      bicho44
      Member

      HI Steve:

      I was a little busy, but i figure out, after you ask me about the get_terms() function.

      And this is the code I made, is not pretty but works, je.

      
      
      $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);
              $catname= remove_accents ( strtolower($categoria->labels->name));
      
              //piklist::pre($categoria);
      
              /*
              * Para saber el Nombre en Singular
              * $categoria->labels->name
               *
               * El valor debe ser url/cat/slug
              */
      
              $url = esc_url( home_url( '/'));
      
              $terms = get_terms($value, array('hide_empty' => false));
      
              /**
               * Here I piece together the url to send the dropdown.
               * Not pretty but works. 
               */
      
              $menu=array();
      
              foreach ($terms as $i => $v){
                  $menu[$url.$catname.'/'.$v->slug] = $v->name;
              }
      
              /* end URL glueing :D */
              
              // Here the piklist part
              
              piklist('field', array(
              'type' => 'select'
              , 'scope' => 'taxonomy'
              , 'field' => $catname
              , 'label' => $categoria->labels->name.' de Productos'
              , 'columns' => '9'
              , 'choices' =>
              array('' => 'Seleccione para buscar') +
      
                      $menu // Array with the links
      
                      ,'attributes' => array(
                          'onchange' => "window.document.location.href=this.options[this.selectedIndex].value;"
                      )
                  )
      
              );
      
          }
      }
      

      If anyone have a better way, please tell me, but for now its working, Yipieee!!!

    • #5347
      Steve
      Keymaster

      I’ve used this in the past and it works pretty well:

      return is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
      
Viewing 5 reply threads
  • You must be logged in to reply to this topic.