Title: Modifying a function
Last modified: December 10, 2023

---

# Modifying a function

 *  [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/)
 * I have:
 *     ```wp-block-code
       /*
        * Routine to display a custom meta box editor
        * Note: In this example our custom meta data is saved as a row in the postmeta database table.
        * $post PostObject An object representing a WordPress post that is currently being loaded in the post editor.
        */
       function camere_meta_box_render( $post ){
   
           // Get the number and display it in a numeric field
           $number = get_post_meta( $post->ID, "function_camere", true );
           echo '<div><select name="function_camere">';
       for( $i = 0; $i < 13; $i++ ) {
         echo '<option value="'.$i.'" '. selected( $number, $i, false ) .' >'.$i.'</option>';
       }
       echo '</select></div>';
   
       }
   
       // Hook into the save routine for posts
       add_action( 'save_post', 'camere_meta_box_save');
   
       /*
        * Routine to save the custom post meta data from the editor
        * Note: We retrieve the form data through the PHP Global $_POST
        * $post_id int The ID of the post being saved
        */
       function camere_meta_box_save( $post_id ){
   
           // Check to see if this is our custom post type (remove this check if applying the meta box globally)
           if($_POST['post_type'] == "post"){
   
               // Retrieve the values from the form
               $number = $_POST['function_camere'];
   
   
               // Clean, sanitize and validate the input as appropriate
   
               // Save the updated data into the custom post meta database table
               update_post_meta( $post_id, "function_camere", $number );
       ```
   
 * I dont need numbers now, but the options are gettexted sentences, how can I echo
   these sentences from a selector?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fmodifying-a-function%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17266193)
 * Gettext requires fixed, static strings so you cannot dynamically generate a select
   list. You’ll need to define each option one at a time. For example:
 *     ```
       echo '<select name="function_camere">';
       $i = __('one','sacconicase');
       echo '<option value="one" '. selected( $saved, 'one', false ) .' >'.$i.'</option>';
       $i = __('two','sacconicase');
       echo '<option value="two" '. selected( $saved, 'two', false ) .' >'.$i.'</option>';
       //etc....
       ```
   
 * In this example, the saved value is always in English, but the displayed options
   are in the current language. This approach has a lot of redundant code, there
   are likely ways to streamline it, but the option label displayed does need to
   be done one at a time.
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17267123)
 * I have a problem because in italian you use the apostrophe and I suppose this
   is interpreted as a single quotation mark from the system. This is what I wrote:
 *     ```wp-block-code
       function introduzione_meta_box_render( $post ){
   
           // Get the number and display it in a numeric field
           $introduzione = get_post_meta( $post->ID, "function_camere", true );
        echo '<div><select name="function_camere">';
       $i = __('L'appartamento si compone di:','sacconicase');
       echo '<option value="L'appartamento si compone di:" '. selected( $saved, 'L'appartamento si compone di:', false ) .' >'.$i.'</option>';
       $i = __('La casa si compone di:','sacconicase');
       echo '<option value="La casa si compone di:" '. selected( $saved, 'La casa si compone di:', false ) .' >'.$i.'</option>';
        }
       echo '</select></div>';
       ```
   
 * I cant avoid writing “L’appartamento”
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17272596)
 * Only the “straight”(`'`) apostrophe is seen as a quote. You can use the “curly”
   kind (`’`) and it will not be seen as a quote. Or use the equivalent entity code`&
   rsquo;` (remove the space after the & that I had to insert to prevent the forum’s
   parser from converting it into a `’`)
 * Another way to use a straight apostrophe in code is to use double quotes:
    `echo"
   L'appartamento";` If you need a double quote to be seen as a character in a double
   quoted string, it can be escaped: `echo "He replied \"Nuts\".";`
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17275187)
 * If I do
 *     ```wp-block-code
       function introduzione_meta_box_render( $post ){
   
           // Get the number and display it in a numeric field
           $introduzione = get_post_meta( $post->ID, "function_camere", true );
        echo '<div><select name="function_camere">';
       $i = __(''L'appartamento si compone di:'','sacconicase');
       echo '<option value="L'appartamento si compone di:" '. selected( $saved, 'L'appartamento si compone di:', false ) .' >'.$i.'</option>';
       $i = __('La casa si compone di:','sacconicase');
       echo '<option value="La casa si compone di:" '. selected( $saved, 'La casa si compone di:', false ) .' >'.$i.'</option>';
        }
       echo '</select></div>';
       ```
   
 * with
 *     ```wp-block-code
       $i = __(''L'appartamento si compone di:'','sacconicase');
       ```
   
 * PhpChecker tells me it’s an error
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17275223)
 * Use one double quote character, not two single quote characters.
    `$i = __("L'appartamento
   si compone di:",'sacconicase');`
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17275673)
 * I still have a problem with
 *     ```wp-block-code
       $i = __("L'appartamento si compone di:",'sacconicase');
       ```
   
 * inside
 *     ```wp-block-code
       function introduzione_meta_box_render( $post ){
           // Get the number and display it in a numeric field
           $introduzione = get_post_meta( $post->ID, "function_camere", true );
        echo '<div><select name="function_camere">';
       $i = __("L'appartamento si compone di:",'sacconicase');
       echo '<option value="L'appartamento si compone di:" '. selected( $saved, "L'appartamento si compone di:", false ) .' >'.$i.'</option>';
       $i = __("La casa si compone di:",'sacconicase');
       echo '<option value="La casa si compone di:" '. selected( $saved, 'La casa si compone di:', false ) .' >'.$i.'</option>';
        }
       echo '</select></div>';
       ```
   
 *  [Ashutosh Sharma](https://wordpress.org/support/users/ashutosharma97/)
 * (@ashutosharma97)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17276005)
 * Your syntax is breaking on the `echo` line because you are not using quotes properly.
   You need to escape quotes when you have nested quotes:
 *     ```wp-block-code
       function introduzione_meta_box_render($post)
       {
           // Get the number and display it in a numeric field
           $introduzione = get_post_meta($post->ID, 'function_camere', true);
           echo '<div><select name="function_camere">';
           $i = __("L'appartamento si compone di:",'sacconicase');
           echo '<option value="L\'appartamento si compone di:" ' . selected($saved, "L'appartamento si compone di:", false) . ' >' . $i . '</option>';
           $i = __('La casa si compone di:', 'sacconicase');
           echo '<option value="La casa si compone di:" ' . selected($saved, 'La casa si compone di:', false) . ' >' . $i . '</option>';
           echo '</select></div>';
       }
       ```
   
 * Or store the value in a variable and use that variable if you are getting confused:
 *     ```wp-block-code
       function introduzione_meta_box_render($post)
       {
           // Get the number and display it in a numeric field
           $introduzione = get_post_meta($post->ID, 'function_camere', true);
           $original_text = "L\'appartamento si compone di:";
           echo '<div><select name="function_camere">';
           $translated_text = __($original_text, 'sacconicase');
           echo '<option value="' . $original_text . '" ' . selected($saved, $original_text, false) . ' >' . $translated_text . '</option>';
   
           $original_text = 'La casa si compone di:';
           $translated_text = __($original_text, 'sacconicase');
           echo '<option value="' . $original_text . '" ' . selected($saved, $original_text, false) . ' >' . $translated_text . '</option>';
           echo '</select></div>';
       }
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Modifying a function’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [Ashutosh Sharma](https://wordpress.org/support/users/ashutosharma97/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/modifying-a-function/#post-17276005)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
