Tagged: , ,

This topic contains 8 replies, has 3 voices, and was last updated by  Steve 5 years, 1 month ago.

  • Author
    Posts
  • #2338

    tuckerjoenz
    Participant

    Hello! Is there a possible way to add a taxonomy inside an add more field? Say I have an add more field group and wanted to have taxonomies only associated with those. Is that possible? Thanks!

  • #2339

    Jason
    Keymaster

    I’m sorry, can you please try explaining that differently? I follow that you have an add_more group and want to do something with it concerning taxonomies, but that’s as much as I’m understanding. Have you tried doing what your explaining? Do you have any code (even not working) that you could show?

  • #2340

    tuckerjoenz
    Participant

    @jason my bad, yes let me show you what I’m trying to do.

    https://www.evernote.com/shard/s42/sh/39c88564-66e5-4da6-bb84-e02d59d2a3c2/f9fb80bc01713627feb80bebd7bf4acb

    That program select I want to make as a taxonomy to be able to be added to and changed. Is this possible? Right now I have just a select hard coded. Here is that code:

    // REPEATED FIELDS
    
      piklist('field', array(
        'type' => 'group'
        ,'field' => 'a_grant'
        ,'add_more' => true
        ,'label' => __('Grants')
        ,'description' => 'Add a grant by clicking the blue plus button.'
        ,'fields' => array(
    
          array(
            'type' => 'checkbox'
            ,'scope' => 'post_meta'
            ,'field' => 'a_active_grant_status'
            ,'label' => 'Active Grant'
            ,'choices' => array(
              'show' => 'Show on partner page?'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
          ,array(
            'type' => 'datepicker'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_year'
            ,'label' => 'Grant Year'
            ,'attributes' => array(
              'class' => 'text'
              ,'placeholder' => 'Pick a Date'
            )
            /*,'options' => array(
              'dateFormat' => 'M, yyyy'
              ,'firstDay' => '0'
            )*/
          )
    
          ,array(
            'type' => 'text'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_amount'
            ,'label' => 'Amount Awarded'
            ,'attributes' => array(
              'class' => 'regular-text'
              ,'placeholder' => 'Amount Awarded'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
    //TAXONOMY?
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_amount_range'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Amount Range'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'Less than $100,000'
              ,'option3' => '$100,000 - $200,000'
              ,'option4' => '$200,000 - $300,000'
              ,'option5' => '$300,000 - $400,000'
              ,'option6' => '$400,000 - $500,000'
              ,'option7' => '$500,000 and more'
            )
          )
    
          ,array(
            'type' => 'text'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_location'
            ,'label' => 'City'
            ,'attributes' => array(
              'class' => 'regular-text'
              ,'placeholder' => 'Grant Location'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
    // TAXONOMY FIELDS
    
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_region'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Region'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'North America'
              ,'option3' => 'South America'
              ,'option4' => 'Europe'
              ,'option5' => 'Asia' 
              ,'option6' => 'Africa'
              ,'option7' => 'Australia'
            )
          )
    
          ,array(
            'type' => 'hidden'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_associated_arcus_type'
            ,'label' => 'Type'
            ,'attributes' => array(
              'class' => 'text'
            )
          )
    
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_associated_arcus_program'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Program'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'Option 1'
              ,'option3' => 'Option 2'
              ,'option4' => 'Option 3'
            )
          )
    
          ,array(
            'type' => 'editor'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_description'
            ,'label' => 'Grant Description'
            ,'options' => array (
              'media_buttons' => false
              ,'teeny' => false
              ,'textarea_rows' => 5
              ,'drag_drop_upload' => false
            )
          )
        )
      ));
  • #2341

    Jason
    Keymaster

    Thanks for posting the code and picture! That helps!

    I’m still a bit unclear as to where the taxonomy fits in all this. Are you saying you want to list taxonomies into a select? or are you trying to list all the terms of a specific taxonomy into a select?

    We’ll get there! 😉

  • #2342

    tuckerjoenz
    Participant

    @jason not a problem. What I want is that Program select to be a taxonomy that can be changed by an admin. Right now I have added a select dropdown. What I don’t want is the taxonomy to be part of the post type in general, just to be associated with the add more group. Here is the entire CPT. Let me know if that helped 🙂

    <?php
    /*
    Title: Partnerss
    Post Type: partnerss
    Order: 13
    Meta Box: false
    Collapse: false
    */
    ?>
    
    <?php
    
      piklist('field', array(
        'type' => 'file'
        ,'field' => 'a_partner_logo'
        ,'scope' => 'post_meta'
        ,'label' => __('Partner Logo')
        ,'description' => 'Pixel dimensions...'
        ,'options' => array(
          'basic' => true
        )
      ));
    
      piklist('field', array(
        'type' => 'text'
        ,'field' => 'a_partner_url'
        ,'label' => 'Partner URL'
        ,'attributes' => array(
          'class' => 'regular-text'
          ,'placeholder' => 'http://'
        )
        ,'on_post_status' => array(
          'value' => 'lock'
        )
      ));
    
      piklist('field', array(
        'type' => 'text'
        ,'field' => 'a_donation_url'
        ,'label' => 'Donation URL'
        ,'attributes' => array(
          'class' => 'regular-text'
          ,'placeholder' => 'http://'
        )
        ,'on_post_status' => array(
          'value' => 'lock'
        )
      ));
    
    // REPEATED FIELDS
    
      piklist('field', array(
        'type' => 'group'
        ,'field' => 'a_grant'
        ,'add_more' => true
        ,'label' => __('Grants')
        ,'description' => 'Add a grant by clicking the blue plus button.'
        ,'fields' => array(
    
          array(
            'type' => 'checkbox'
            ,'scope' => 'post_meta'
            ,'field' => 'a_active_grant_status'
            ,'label' => 'Active Grant'
            ,'choices' => array(
              'show' => 'Show on partner page?'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
          ,array(
            'type' => 'datepicker'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_year'
            ,'label' => 'Grant Year'
            ,'attributes' => array(
              'class' => 'text'
              ,'placeholder' => 'Pick a Date'
            )
            /*,'options' => array(
              'dateFormat' => 'M, yyyy'
              ,'firstDay' => '0'
            )*/
          )
    
          ,array(
            'type' => 'text'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_amount'
            ,'label' => 'Amount Awarded'
            ,'attributes' => array(
              'class' => 'regular-text'
              ,'placeholder' => 'Amount Awarded'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
    //TAXONOMY?
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_amount_range'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Amount Range'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'Less than $100,000'
              ,'option3' => '$100,000 - $200,000'
              ,'option4' => '$200,000 - $300,000'
              ,'option5' => '$300,000 - $400,000'
              ,'option6' => '$400,000 - $500,000'
              ,'option7' => '$500,000 and more'
            )
          )
    
          ,array(
            'type' => 'text'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_location'
            ,'label' => 'City'
            ,'attributes' => array(
              'class' => 'regular-text'
              ,'placeholder' => 'Grant Location'
            )
            ,'on_post_status' => array(
              'value' => 'lock'
            )
          )
    
    // TAXONOMY FIELDS
    
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_region'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Region'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'North America'
              ,'option3' => 'South America'
              ,'option4' => 'Europe'
              ,'option5' => 'Asia' 
              ,'option6' => 'Africa'
              ,'option7' => 'Australia'
            )
          )
    
          ,array(
            'type' => 'hidden'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_associated_arcus_type'
            ,'label' => 'Type'
            ,'attributes' => array(
              'class' => 'text'
            )
          )
    
          ,array(
            'type' => 'select'
            ,'scope' => 'post_meta' // Not used for settings sections
            ,'field' => 'a_grant_associated_arcus_program'
            ,'value' => 'option1' // Sets default to Option 1
            ,'label' => 'Program'
            ,'attributes' => array(
              'class' => 'text'
            )
            ,'choices' => array(
              'option1' => NULL
              ,'option2' => 'Option 1'
              ,'option3' => 'Option 2'
              ,'option4' => 'Option 3'
            )
          )
    
          ,array(
            'type' => 'editor'
            ,'scope' => 'post_meta'
            ,'field' => 'a_grant_description'
            ,'label' => 'Grant Description'
            ,'options' => array (
              'media_buttons' => false
              ,'teeny' => false
              ,'textarea_rows' => 5
              ,'drag_drop_upload' => false
            )
          )
        )
      ));
    
    /*
    
      piklist('field', array(
         'type' => 'datepicker'
         ,'field' => 'arcus_date'
         ,'label' => 'Grantee Year'
         ,'description' => 'Grantee Year'
         ,'attributes' => array(
           'class' => 'text'
         )
        ,'options' => array(
           'dateFormat' => 'M, yyyy'
           ,'firstDay' => '0'
        )
      ));
    
    */
    
      echo '<h3>Related Partners</h3>';
    
      piklist('field', array(
        'type' => 'post-relate'
        ,'scope' => 'Partners'
        ,'template' => 'field'
      ));
    
      echo '<h3>Related Stories</h3>';
    
      piklist('field', array(
        'type' => 'post-relate'
        ,'scope' => 'stories'
        ,'template' => 'field'
      ));
    
      echo '<h3>Related News</h3>';
    
      piklist('field', array(
        'type' => 'post-relate'
        ,'scope' => 'post'
        ,'template' => 'field'
      ));
    
      echo '<h3>Related Publications</h3>';
    
      piklist('field', array(
        'type' => 'post-relate'
        ,'scope' => 'publications'
        ,'template' => 'field'
      ));
  • #2344

    Jason
    Keymaster

    Ah, I think I see what you’re saying. So you want the Program select to be an adjustable list of items. A combobox is what’s coming to mind: http://jsfiddle.net/ivkremer/yq2TD/

    Is that along what you’re thinking? Otherwise you can’t have a disassociated taxonomy; it has to belong to a post type. You could always create a post type that’s publicly invisible or create an admin page and have the list generated from an add_more there.

    Help me to know if I’m thinking in the right direction.

  • #2345

    tuckerjoenz
    Participant

    that’s what I thought. I was hoping there was a simple way to add customization to the select for Programs for the client, but I think we will have to just go with a standard select for now. Thanks Jason!

  • #2347

    Jason
    Keymaster

    I wouldn’t say it’s a limitation of the select field in Piklist, as much as in general. Outside of a fields that provides options as you search, I can’t think of a UI element that provides options while simultaneously being changeable. Sort of defeats the purpose.

    If I really want fields, in Piklist, to be definable, and they don’t come from a post type, taxonomy, etc., then I often make a “Settings” section somewhere and provide the ability to define stuff there. So, for example, I’d have a “Programs” repeatable text field. I’d then pull the options when making the meta-box and use those for the list.

    Hope this helps!

  • #2350

    Steve
    Keymaster

The topic ‘Taxonomies inside add more advanced fields in custom post types’ is closed to new replies.