More than one taxonomy/taxonomy_advanced field = last instance overrides others

Support General More than one taxonomy/taxonomy_advanced field = last instance overrides othersResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #24611
    AlexAlex
    Participant

    When adding more than one taxonomy or taxonomy_advanced fields to a post/page with different and unique ids, all fields simply save the value of the last one present. In the example below, whatever value is selected for category_feed becomes the saved value for both category_feed and category_feed_short regardless of what is selected for category_feed_short. How do I add multiple category select fields with ability to save a different selection for each?

    function stories_custom_fields($meta_boxes) {
      $prefix = 'category_feed_short_';
      $meta_boxes[] = array(
        'id' => 'category_feed_short',
        'title' => 'Article feed by category - Short format',
        'context' => 'normal',
        'priority' => 'default',
        'autosave' => true,
        'post_types' => array('page'),
        'include' => array(
          'template' => array('page-originals-single.php')
        ),
        'fields' => array(
          array(
            'id' => $prefix . 'headline',
            'name' => 'Headline',
            'desc' => 'Default: Find out more',
            'type' => 'text',
          ),
          array(
            'name' => 'Category',
            'id' => $prefix . 'select',
            'type' => 'taxonomy_advanced',
            'taxonomy' => 'category',
            'field_type' => 'select_advanced',
            'multiple' => false
          )
        )
      );
    
    $prefix = 'category_feed_';
      $meta_boxes[] = array(
        'id' => 'category_feed',
        'title' => 'Article feed by category - Article format',
        'context' => 'normal',
        'priority' => 'default',
        'autosave' => true,
        'post_types' => array('page'),
        'include' => array(
          'template' => array('page-originals-single.php')
        ),
        'fields' => array(
          array(
            'id' => $prefix . 'headline',
            'name' => 'Headline',
            'desc' => esc_html__('Default: A deeper look'),
            'type' => 'text',
          ),
          array(
            'name' => 'Category',
            'id' => $prefix . 'select',
            'type' => 'taxonomy_advanced',
            'taxonomy' => 'category',
            'field_type' => 'select_advanced',
            'multiple' => false
          )
        )
      );
      return $meta_boxes;
    }
    
    add_filter('rwmb_meta_boxes', 'stories_custom_fields');
    #24617
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I do not see any issue with your code when testing on my local site. Screen record https://share.getcloudapp.com/04uJWOGK.

    You can try to use different variable $prefix to re-check it.

    $prefix1 = 'category_feed_short_';
    $prefix2 = 'category_feed_';
    #24618
    AlexAlex
    Participant

    Ok, thanks for testing. Must be a conflict / something specific with my site. Will figure it out. Please feel free to mark as resolved.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.