Tagged: ,

This topic contains 5 replies, has 2 voices, and was last updated by  Steve 4 years ago.

  • Author
  • #4154


    Hi! 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?

  • #4156


    @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.

  • #4165


    Hmm, 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
  • #4166


    @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, like festivalsawards.

    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.

  • #4171


    Thanks 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.

  • #4175


    Great! Closing ticket.

The topic ‘Displaying an Editor Field’ is closed to new replies.