Tagged: 

Viewing 10 reply threads
  • Author
    Posts
    • #2767
      deon
      Member

      Note: I’m from Brazil and I’m translating the text by google translate ..

      Created a CPT and a taxonomy. I put the code metabox and it appears correctly as planned, however, when I publish the post, nothing is saved and the options are blank. What could be happening?

      ——————
      My code in functions.php
      http://pastebin.com/4BAWwwes

      My code in metabox:
      piklist(‘field’, array(
      ‘type’ => ‘checkbox’
      ,’scope’ => ‘demo-type’
      ,’field’ => ‘category’
      ,’label’ => ‘Categorias’
      ,’description’ => ‘Terms will appear when they are added to this taxonomy.’
      ,’choices’ => piklist(get_terms(‘piklist_demo_type’, array(‘hide_empty’ => false))
      ,array(‘term_id’ ,’name’))
      ));

      Thanks in advance.

      Attachments:
      You must be logged in to view attached files.
    • #2771
      Steve
      Keymaster

      Hi Deon– For most situations you do not have to define “scope”. Piklist will do it automatically for you. Just remove scope from the field:

      piklist('field', array(
        'type' => 'checkbox'
        ,'field' => 'category'
        ,'label' => 'Categorias'
        ,'description' => 'Terms will appear when they are added to this taxonomy.'
        ,'choices' => piklist(
            get_terms('piklist_demo_type',array(
              'hide_empty' => false
            ))
           ,array(
            'term_id'
            ,'name'
           )
        )
      ));
      
    • #2772
      deon
      Member

      Oh, it worked! Thank you so much.

      I am using the following code to reproduce the data:
      get_post_meta ($ post-> ID, 'category', true);

      However it returns me as number .. and not as options, how can I do?

      Again, thank you!

    • #2773
      Steve
      Keymaster

      @deon– Great! Glad it worked.

      This part of the field is telling Piklist to save the data as the term_id, and display the name, which is the way WordPress works (save ID’s).

      ,array(
            'term_id'
            ,'name'
           )
      

      Here’s how you can display the term name:

      $term_id = get_post_meta ($post-> ID, 'category', true); // Get the term ID.
      
      $term_info = get_term_by('id', $term_id, 'category'); // Get the term info.
      
      print_r($term_info); // Display all term info.
      
    • #2774
      deon
      Member

      Many thanks Steve, it took me to answer because I’m trying to make it appear all selected .. I’ve tried “get_the_therms” foreach .. and I did not get a result.

      What do you suggest me to try?

    • #2775
      Steve
      Keymaster

      @deon– Does this work? (modified code from WordPress codex)

      $terms = get_the_terms($post->ID, 'category');
      						
      if ($terms && !is_wp_error($terms)) : 
      
        $category_links = array();
      
        foreach ($terms as $term)
        {
          $category_links[] = $term->name;
        }
      						
        $category = join( ", ", $category_links );
      
        echo $category;
      
      endif;
      
    • #2776
      deon
      Member

      I like your solution, however selected boxs not appear on the site 🙁

    • #2777
      Steve
      Keymaster

      @deon– I don’t think I understand what you want. Can you send a screenshot or drawing?

    • #2778
      deon
      Member

      Where should appear the names are blank. This is what is happening.

    • #3796
      Quang Anh
      Member

      Hi Deon,

      You should try something like this, it work for me !

      $term_ids = get_post_meta($post_id, 'restaurant_cuisine', false); // Get the term IDs
      
              foreach ($term_ids as $term_id) {
                echo $term_id;
                $term_info = get_term_by('id', $term_id, 'cuisine');
                echo $term_info->name;
              }

      I think that the way you want, taxonomy store in post_meta, and you must extract to get that informations.

    • #3802
      Steve
      Keymaster

      @quanganh– Thanks for the help!

      Closing ticket.

Viewing 10 reply threads
  • The topic ‘My field is not saved’ is closed to new replies.