Viewing 7 reply threads
  • Author
    Posts
    • #7441
      torarnv
      Member

      I’m trying to save a taxonomy from a font-end-form for a custom post type:

      piklist('field', array(
      	'type' => 'hidden',
      	'scope' => 'post',
      	'field' => 'post_type',
      	'value' => 'foo',
      ));
      
      piklist('field', array(
        'type' => 'radio'
        ,'scope' => 'taxonomy'
        ,'field' => 'bar'
        ,'label' => 'Bar'
        ,'description' => 'Bar'
        ,'choices' => piklist(get_terms(array(
            'taxonomy' => 'bar'
            ,'hide_empty' => false
          ))
          ,array(
            'term_id'
            ,'name'
          )
        )
      ));
      

      Which errors out in class-piklist-form.php on the line $field['object_id'] = $field['object_id'] ? $field['object_id'] : $object_ids[$wp_taxonomies[$taxonomy]->object_type[0]]; since object_ids contains ‘post’, not ‘foo’;

      I had to change the logic for appending to object_ids to the following:

      
      $post_type = !empty($object['post_type']) ? $object['post_type'] : $scope;
      
      if (!isset($object_ids[$post_type]))
      {
        $object_ids[$post_type] = $result_id;
      }

      Dunno if this is the right approach.

    • #7477
      Steve
      Keymaster

      Just replace ‘foo’ with the name of your Post Type.

    • #7642
      hozefasmile
      Member

      Hi @Steve,

      Do you have any idea why my post category are not saving for this form? http://uniquesweb.co.in/piklist/submit-book/
      I have used this field in frontend form file

      piklist('field', array(
      
          'type'        => 'select'
      
          ,'scope'       => 'taxonomy'
      
          ,'field'       => 'book_type'
      
          ,'choices' => piklist(get_terms('book_category', array(
      
                  'hide_empty' => false
      
              )), array(
      
                  'term_id'
      
                  ,'name'
      
              )
      
          )
      
          ,'required' => true,
      
      ));

      and this is how my custom post type and custom taxonomy is created in theme’s function.php file

      function create_book_custom_post_type() {
      
      	$labels = array(
      		'name'                  => _x( 'Books', 'Post Type General Name', 'bootstrap-basic' ),
      		'singular_name'         => _x( 'Book', 'Post Type Singular Name', 'bootstrap-basic' ),
      		'menu_name'             => __( 'Books', 'bootstrap-basic' ),
      		'name_admin_bar'        => __( 'Book', 'bootstrap-basic' ),
      		'archives'              => __( 'Book Archives', 'bootstrap-basic' ),
      		'attributes'            => __( 'Book Attributes', 'bootstrap-basic' ),
      		'parent_item_colon'     => __( 'Parent Book:', 'bootstrap-basic' ),
      		'all_items'             => __( 'All Books', 'bootstrap-basic' ),
      		'add_new_item'          => __( 'Add New Book', 'bootstrap-basic' ),
      		'add_new'               => __( 'Add New', 'bootstrap-basic' ),
      		'new_item'              => __( 'New Book', 'bootstrap-basic' ),
      		'edit_item'             => __( 'Edit Book', 'bootstrap-basic' ),
      		'update_item'           => __( 'Update Book', 'bootstrap-basic' ),
      		'view_item'             => __( 'View Book', 'bootstrap-basic' ),
      		'view_items'            => __( 'View Books', 'bootstrap-basic' ),
      		'search_items'          => __( 'Search Book', 'bootstrap-basic' ),
      		'not_found'             => __( 'Not found', 'bootstrap-basic' ),
      		'not_found_in_trash'    => __( 'Not found in Trash', 'bootstrap-basic' ),
      		'featured_image'        => __( 'Featured Image', 'bootstrap-basic' ),
      		'set_featured_image'    => __( 'Set featured image', 'bootstrap-basic' ),
      		'remove_featured_image' => __( 'Remove featured image', 'bootstrap-basic' ),
      		'use_featured_image'    => __( 'Use as featured image', 'bootstrap-basic' ),
      		'insert_into_item'      => __( 'Insert into Book', 'bootstrap-basic' ),
      		'uploaded_to_this_item' => __( 'Uploaded to this Book', 'bootstrap-basic' ),
      		'items_list'            => __( 'Books list', 'bootstrap-basic' ),
      		'items_list_navigation' => __( 'Books list navigation', 'bootstrap-basic' ),
      		'filter_items_list'     => __( 'Filter Books list', 'bootstrap-basic' ),
      	);
      	$rewrite = array(
      		'slug'                  => 'book',
      		'with_front'            => true,
      		'pages'                 => true,
      		'feeds'                 => true,
      	);
      	$args = array(
      		'label'                 => __( 'Book', 'bootstrap-basic' ),
      		'labels'                => $labels,
      		'supports'              => array( 'title', 'excerpt', 'author', 'thumbnail', 'revisions', ),
      		'taxonomies'            => array( 'book_category' ),
      		'hierarchical'          => false,
      		'public'                => true,
      		'show_ui'               => true,
      		'show_in_menu'          => true,
      		'menu_position'         => 25,
      		'menu_icon'             => 'dashicons-format-aside',
      		'show_in_admin_bar'     => true,
      		'show_in_nav_menus'     => true,
      		'can_export'            => true,
      		'has_archive'           => 'books',
      		'exclude_from_search'   => false,
      		'publicly_queryable'    => true,
      		'rewrite'               => $rewrite,
      		'capability_type'       => 'post',
      	);
      	register_post_type( 'book', $args );
      
      }
      add_action( 'init', 'create_book_custom_post_type', 0 );
      function create_book_custom_taxonomy() {
      
      	$labels = array(
      		'name'                       => _x( 'Book Categories', 'Taxonomy General Name', 'bootstrap-basic' ),
      		'singular_name'              => _x( 'Book Category', 'Taxonomy Singular Name', 'bootstrap-basic' ),
      		'menu_name'                  => __( 'Book Category', 'bootstrap-basic' ),
      		'all_items'                  => __( 'All Book Categories', 'bootstrap-basic' ),
      		'parent_item'                => __( 'Parent Book Category', 'bootstrap-basic' ),
      		'parent_item_colon'          => __( 'Parent Book Category:', 'bootstrap-basic' ),
      		'new_item_name'              => __( 'New Book Category Name', 'bootstrap-basic' ),
      		'add_new_item'               => __( 'Add New Book Category', 'bootstrap-basic' ),
      		'edit_item'                  => __( 'Edit Book Category', 'bootstrap-basic' ),
      		'update_item'                => __( 'Update Book Category', 'bootstrap-basic' ),
      		'view_item'                  => __( 'View Book Category', 'bootstrap-basic' ),
      		'separate_items_with_commas' => __( 'Separate items with commas', 'bootstrap-basic' ),
      		'add_or_remove_items'        => __( 'Add or remove Book Categories', 'bootstrap-basic' ),
      		'choose_from_most_used'      => __( 'Choose from the most used', 'bootstrap-basic' ),
      		'popular_items'              => __( 'Popular Book Categories', 'bootstrap-basic' ),
      		'search_items'               => __( 'Search Book Categories', 'bootstrap-basic' ),
      		'not_found'                  => __( 'Not Found', 'bootstrap-basic' ),
      		'no_terms'                   => __( 'No Book Categories', 'bootstrap-basic' ),
      		'items_list'                 => __( 'Book Categories list', 'bootstrap-basic' ),
      		'items_list_navigation'      => __( 'Book Categories list navigation', 'bootstrap-basic' ),
      	);
      	$rewrite = array(
      		'slug'                       => 'book_category',
      		'with_front'                 => true,
      		'hierarchical'               => false,
      	);
      	$args = array(
      		'labels'                     => $labels,
      		'hierarchical'               => true,
      		'public'                     => true,
      		'show_ui'                    => true,
      		'show_admin_column'          => true,
      		'show_in_nav_menus'          => true,
      		'show_tagcloud'              => true,
      		'rewrite'                    => $rewrite,
      	);
      	register_taxonomy( 'book_category', array( 'book' ), $args );
      
      }
      add_action( 'init', 'create_book_custom_taxonomy', 0 );

      All other fields are saving correctly in their place for the custom post type book, only the category that I choose in front end form doesn’t work and remains unselected for the post in wp-admin.

      Please help where I am doing wrong?

    • #7643
      Steve
      Keymaster

      I don’t see a taxonomy named book_type registered.

    • #7645
      hozefasmile
      Member

      Hi Steve,

      I have changed the field value to ‘book_category’ , the taxonomy created, but still the result is same, no taxonomy being saved.
      Now my category choosing field looks like this:-

      piklist('field', array(
          'type'        => 'select'
          ,'scope'       => 'taxonomy'
          ,'field'       => 'book_category'
          ,'choices' => piklist(get_terms('book_category', array(
                  'hide_empty' => false
              )), array(
                  'term_id'
                  ,'name'
              )
          )
          ,'required' => true,
      ));

      , but still not working 🙁

    • #7658
      Steve
      Keymaster

      Looks like this is a bug in front end forms and taxonomies.

    • #7796
      Stephen
      Participant

      I am having this same issue, taxonomy items from front end are not saving. Is there a workaround or bugfix somewhere?

    • #7860
      jessor
      Participant

      +1 (subscribing)

Viewing 7 reply threads
  • You must be logged in to reply to this topic.