Tagged: hidden, piklist_save_field, title
- This topic has 6 replies, 2 voices, and was last updated 2 years, 7 months ago by
thor.
-
AuthorPosts
-
-
May 19, 2019 at 3:44 pm #9388
thorMemberI have a regular text field that holds a custom title (‘custom_title’) for the post. The title has a few “reserved” characters for soft hyphenation and line breaks (easy for the “non-tech-savvy” user to understand).
I want to save that title to a an extra hidden field with the linebreaks as html tags. I know how to do that, but how do I pull the custom title field to the hidden? Do I need to hook into ‘piklist_save_field’? I would love to have it as a part of a the sanitization filter that I am already using to strip out extra spaces on the ‘custom_title’.
-
May 24, 2019 at 6:32 am #9391
SteveKeymasterYou can create a hidden field by setting the field type to hidden.
-
June 3, 2019 at 2:44 pm #9400
thorMemberThanks Steve, I know how to create the hidden field. But how can it use the non-hidden text field? So I have the hidden field with the HTML version of the custom_title?
I can run a manual ‘update_post_meta’ in my sanitize callback where I store the HTML version in a meta field. But this is not ideal for serialized arrays (when I have used Group fields) -
June 6, 2019 at 1:14 pm #9403
SteveKeymasterCan you post some code so we can take a look?
-
June 11, 2019 at 4:14 am #9406
thorMemberRight know I have this meta-box field
/* Title: Intro Post Type: projects */ piklist('field', array( 'type' => 'text', 'field' => 'project_introtitle', 'label' => 'Project title', 'columns' => 4, 'sanitize' => array( array( 'type' => 'title_sanitization', // defined in functions.php (piklist-functions.php) 'options' => 'html' // used as custom field suffix ) ), 'attributes' => array( 'placeholder' => get_the_title() ) ));In functions.php I have this sanitization and a bit of a hack for saving the field in a html version:
// Piklist sanitize titles (Allow forced breaks) and soft hyphens add_filter('piklist_sanitization_rules', 'sanitize_title_function', 11); function sanitize_title_function($sanitization_rules) { $sanitization_rules['title_sanitization'] = array( 'callback' => 'sanitize_title_callback' ); return $sanitization_rules; } function sanitize_title_callback($value, $field, $options) { $returntitle = trim(preg_replace('/\s+/', ' ', $value)); // removes any extra (unwanted) spaces $postid = intval( $field["object_id"] ); $this_field = $field["field"]; if (isset($options) && '' !== $options && !is_array($options)) { $suffix = '_' .sanitize_html_class($options); $htmltitle = str_replace('|', '<br />', $returntitle); $htmltitle = str_replace('_', '­', $htmltitle); update_post_meta( $postid, $this_field . $suffix, $htmltitle ); // extra meta (using suffix) } return $returntitle; }So this is a bit hacky, and it will not work serialized arrays. So what would be the proper solution – saving to a hidden piklist field that works with groups and repeaters?
-
June 20, 2019 at 11:44 am #9414
SteveKeymasterI’m still confused. I don’t see a reference to a hidden field.
-
June 20, 2019 at 1:34 pm #9417
thorMemberHi Steven
I know how to create a hidden field – I just don’t know how to have one value from a piklist field saved into another (the hidden).
Field A (text) holds ‘This is my title| with a special character’
Field B (hidden) should save Field A in a HTML format ‘This is my title<br/> with a special character’
-
-
AuthorPosts
- You must be logged in to reply to this topic.