Viewing 5 reply threads
  • Author
    Posts
    • #3589
      Gregg
      Member

      Hi Steve

      I successfully created a taxonomy dropdown list for a CPT that’s employed on my widgets page as you can see in the attached.

      It lists the available taxonomies, but is there a way to have an “All categories” option in the list?

      Attachments:
      You must be logged in to view attached files.
    • #3591
      jcrist
      Member

      You could store the choices as a variable, add “All Categories” with a value of -1, then use ksort:

      $choices = piklist(
            get_terms('category', array(
              'hide_empty' => false
            ))
            ,array(
              'term_id'
              ,'name'
            ));
      $choices[-1] = 'All Categories';
      ksort($choices);

      Then references $choices as the…choices

    • #3593
      Gregg
      Member

      Can you just clarify where the code you recommend should go. Here’s what I have:

      piklist('field', array(
          'type' => 'select'
          ,'field' => 'category'
          ,'label' => 'Categories'
          ,'conditions' => array(
            array(
              'field' => 'gwfg_carousel_content_type'
              ,'value' => 'videos'
            )
          )
          ,'choices' => piklist(
            get_terms('gwfg_video_type', array(
              'hide_empty' => false
            ))
            ,array(
              'term_id'
              ,'name'
            )
          )
        ));

      Thanks.

    • #3597
      jcrist
      Member

      This should do it:

      $choices = piklist(
            get_terms('gwfg_video_type', array(
              'hide_empty' => false
            ))
            ,array(
              'term_id'
              ,'name'
            ));
      $choices[-1] = 'All Categories';
      ksort($choices);
      
      piklist('field', array(
          'type' => 'select'
          ,'field' => 'category'
          ,'label' => 'Categories'
          ,'conditions' => array(
            array(
              'field' => 'gwfg_carousel_content_type'
              ,'value' => 'videos'
            )
          )
          ,'choices' => $choices
        ));
    • #3602
      Gregg
      Member

      Thanks @jcrist and Steve … works like a charm.

    • #3606
      Steve
      Keymaster

      Thanks for the help @jcrist! Closing ticket.

Viewing 5 reply threads
  • The topic ‘Taxonomy Dropdown List – All categories option’ is closed to new replies.