- This topic has 5 replies, 2 voices, and was last updated 6 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
August 5, 2015 at 6:05 pm #4154
cosmocanuckMemberHi! I’d like to include an extra Editor field for adding a certain category of information to posts. But I can’t figure out how to display it… and it looks like there might be a typo on the user guide page for this field type (?).
The first example given is:
echo wpautop(get_post_meta($post->ID, 'field_name, true));However I notice a single quote mark before field_name in the above code, which I presume is an error (and indeed throws a PHP error if I try it).
However when I substitute my field name, and remove the quote mark, I get the error message:
Use of undefined constant awards – assumed ‘awards’ in /home2/vjffs122/public_html/wordpress/wp-content/themes/genesis-sample/single-event.php on line 67
Am I approaching this the wrong way?
-
August 5, 2015 at 10:36 pm #4156
SteveKeymaster@cosmocanuck– Quotes need to go around the meta key:
echo wpautop(get_post_meta($post->ID, 'field_name', true));
I also updated the doc page to fix this typo.
Let me know if this works for you.
-
August 6, 2015 at 7:33 pm #4165
cosmocanuckMemberHmm, now the problem seems to be that no content in my Editor field gets saved! Yipes!
As soon as I hit “Update” on the post… it clears out.
Here’s the code I’m using to add the field:
piklist('field', array( 'type' => 'editor' ,'scope' => 'post' ,'field' => 'festivalsawards' ,'label' => __('Festivals and Awards') ,'options' => array ( 'wpautop' => true ,'media_buttons' => false ,'tabindex' => '' ,'editor_css' => '' ,'editor_class' => '' ,'teeny' => false ,'dfw' => false ,'tinymce' => true ,'quicktags' => true ) )); -
August 6, 2015 at 8:22 pm #4166
SteveKeymaster@cosmocanuck– In most instances the scope is the database table to save to. In your code, you’re setting
'scope' => 'post'. The wp_posts table only allows you to save to existing fields, not create a new one, likefestivalsawards.My guess is that you actually want to save your data to wp_postmeta, which would be
'scope' => 'post_meta'. The only reason to set it to'scope' => 'post'is if you wanted to replace the default editor.In most cases for forms in wp-admin, you don’t even have to set the scope, you can let Piklist automatically set it for you.
Let me know if that makes sense.
-
August 7, 2015 at 11:54 am #4171
cosmocanuckMemberThanks Steve! It does indeed make sense, and my error was in neglecting to delete that line assigning scope from the sample code on the User Guide site (which I had copied)! It’s working perfectly now.
-
August 7, 2015 at 9:39 pm #4175
SteveKeymasterGreat! Closing ticket.
-
-
AuthorPosts
- The topic ‘Displaying an Editor Field’ is closed to new replies.