Tagged: scope
- This topic has 10 replies, 3 voices, and was last updated 6 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
November 12, 2014 at 10:34 am #2767
deonMemberNote: 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/4BAWwwesMy 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. -
November 12, 2014 at 11:01 am #2771
SteveKeymasterHi 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' ) ) )); -
November 12, 2014 at 11:19 am #2772
deonMemberOh, 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!
-
November 12, 2014 at 11:28 am #2773
SteveKeymaster@deon– Great! Glad it worked.
This part of the field is telling Piklist to save the data as the
term_id, and display thename, 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. -
November 12, 2014 at 12:01 pm #2774
deonMemberMany 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?
-
November 12, 2014 at 12:30 pm #2775
SteveKeymaster@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; -
November 12, 2014 at 12:54 pm #2776
deonMemberI like your solution, however selected boxs not appear on the site 🙁
-
November 12, 2014 at 1:00 pm #2777
-
November 12, 2014 at 1:04 pm #2778
deonMemberWhere should appear the names are blank. This is what is happening.
-
June 1, 2015 at 11:04 pm #3796
Quang AnhMemberHi 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.
-
June 2, 2015 at 11:39 am #3802
-
-
AuthorPosts
- The topic ‘My field is not saved’ is closed to new replies.