• I still have problem with updating/sanitizing the following:

    //DESCRIZIONE -DE
    
    
    add_action( 'add_meta_boxes_post', "description_de_add_meta_box" );
    
    /*
     * Routine to add a meta box.  Called via a filter hook once WordPress is initialized
     */
    function description_de_add_meta_box(){
        add_meta_box(
            "description_de_meta_box",  // An ID for the Meta Box.  Make it unique to your plugin
            __( "Descrizione_DE", 'textdomain' ),  // The title for your Meta Box
            "description_de_meta_box_render",  // A callback function to fill the Meta Box with the desired UI in the editor
            "post",  // The screen name - in this case the name of our custom post type
            "side"  // The context or placement for the meta box.  Choose "normal", "side" or "advanced"
        );
    }
    
    /*
     * 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 description_de_meta_box_render( $post ){
    
        // Get the name and display it in a text field
        $description_de = get_post_meta( $post->ID, "description_de", true );
        echo '<div><textarea id="description_de" name="description_de" rows="5" cols="30" class="regular-text" style="width: 700px;"  value="'.$description_de.'" placeholder="Descrizione-DE" /></textarea></div>';
      
    }
    
       
    
    
    // Hook into the save routine for posts
    add_action( 'save_post', 'description_de_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 description_de_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
            $description_de = $_POST['description_de'];
            
    
            // Clean, sanitize and validate the input as appropriate
    
            // Save the updated data into the custom post meta database table
    
    
    update_post_meta( $post_id, 'description_de', sanitize_textarea_field( $_POST['description_de'])); 

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Other than the code you posted is missing the closing }} it seems to work as intended. Data entered in the field gets saved in postmeta under the key “description_de”.

    Is there something else that should be happening that I’m unaware of? What problems are you encountering?

    Thread Starter sacconi

    (@sacconi)

    In my code there are the 2 final }} , I simply copied and pasted badly, but it doesnt work ??

    I type something in the field, I update the post, then I reload the editor page and I cant see what I had typed

    //DESCRIZIONE -DE
    
    
    add_action( 'add_meta_boxes_post', "description_de_add_meta_box" );
    
    /*
     * Routine to add a meta box.  Called via a filter hook once WordPress is initialized
     */
    function description_de_add_meta_box(){
        add_meta_box(
            "description_de_meta_box",  // An ID for the Meta Box.  Make it unique to your plugin
            __( "Descrizione_DE", 'textdomain' ),  // The title for your Meta Box
            "description_de_meta_box_render",  // A callback function to fill the Meta Box with the desired UI in the editor
            "post",  // The screen name - in this case the name of our custom post type
            "side"  // The context or placement for the meta box.  Choose "normal", "side" or "advanced"
        );
    }
    
    /*
     * 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 description_de_meta_box_render( $post ){
    
        // Get the name and display it in a text field
        $description_de = get_post_meta( $post->ID, "description_de", true );
        echo '<div><textarea id="description_de" name="description_de" rows="5" cols="30" class="regular-text" style="width: 700px;"  value="'.$description_de.'" placeholder="Descrizione-DE" /></textarea></div>';
      
    }
    
       
    
    
    // Hook into the save routine for posts
    add_action( 'save_post', 'description_de_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 description_de_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
            $description_de = $_POST['description_de'];
            
    
            // Clean, sanitize and validate the input as appropriate
    
            // Save the updated data into the custom post meta database table
    
    
    update_post_meta( $post_id, 'description_de', sanitize_textarea_field( $_POST['description_de']));  
                           
    
        }     
    }
    
    Moderator bcworkz

    (@bcworkz)

    Ah, I didn’t check on reload when I tested.

    You’re missing the German meta value in the textarea’s content. Corrected line:
    echo '<div><textarea id="description_de" name="description_de" rows="5" cols="30" class="regular-text" style="width: 700px;" value="'.$description_de.'" placeholder="Descrizione-DE" />'.$description_de.'</textarea></div>';

    Thread Starter sacconi

    (@sacconi)

    Perfect! It works. I wondered if I can put an ID=”something” inside because I’l like to define via css it is a paragraph, is it possible? And the beginning of the description (it has another field) will be an H3 or H2 title.

    I’m worried about the indexation in google. If I replace default wp description with a shortcode content maybe Yoast and google dont see that part of the content correctly…

    Moderator bcworkz

    (@bcworkz)

    You may add an id attribute to any HTML tag, assuming it doesn’t already have one. Ensure the assigned id value is different than any other id value on the page. How to do so depends on what’s generating the HTML tag in question.

    Search bots will only see content like a not logged in visitor would. They will see shortcodes already expanded. I don’t know about Yoast. Check things that it outputs to see if there are signs of problems. Check things like its sitemap and Open Graph tags (like the og:title meta tag). There’s possibly a way to correct any issues found with Yoast.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘sanitize_textarea’ is closed to new replies.