• Resolved Valcsi

    (@valcsi)


    I hope someone can help me with my problem.

    I wanted to add some extra custom fields for my custom post type. Firstly I used the Advanced Custom Fields plugin, added the needed custom fields and use them on the site the <?php the_field?> tag. After some time the site caused computer freezing when I’d refreshed it. Sometimes it gave me the bad_pool_header error message sometimes it just froze.

    I decided to reinstall the whole WordPress and use custom meta boxes instead. I add the following code to my functions.php

    // Adds a meta box to the post editing screen
    function reggae_videodetails() {
    add_meta_box( 'reggae_videodetails', __( 'Részletek', 'reggae_videodetails' ), 'reggae_videodetails_callback', 'video', 'normal', 'high' );
    }
    add_action( 'add_meta_boxes', 'reggae_videodetails' );
    
    //Outputs the content of the meta box
    function reggae_videodetails_callback( $post ) {
     wp_nonce_field( basename( __FILE__ ), 'video_nonce' );
        $videodetails_stored_meta = get_post_meta( $post->ID );
        ?>
    
    <table width="100%">
    <tr><td colspan="2"><a href="https://img.youtube.com/vi/VIDEO_ID/mqdefault.jpg" target="_blank">https://img.youtube.com/vi/VIDEO_ID/mqdefault.jpg</a></td></tr>
    <tr><td><p>
     <label for="eloado" class="prfx-row-title"><?php _e( 'El?adó', 'reggae_videodetails' )?></label>
     <input type="text" size="40" name="eloado" id="eloado" value="<?php if ( isset ( $videodetails_stored_meta['eloado'] ) ) echo $videodetails_stored_meta['eloado'][0]; ?>" />
     </p></td><td><p>
     <label for="cim" class="prfx-row-title"><?php _e( 'Cím', 'reggae_videodetails' )?></label>
     <input type="text" size="40" name="cim" id="cim" value="<?php if ( isset ( $videodetails_stored_meta['cim'] ) ) echo $videodetails_stored_meta['cim'][0]; ?>" />
     </p></td></tr></table>
    
    <?php
    }
    //Saves the custom meta input
    function reggae_videodetails_save( $post_id ) {
    
    // Checks save status
    $is_autosave = wp_is_post_autosave( $post_id );
    $is_revision = wp_is_post_revision( $post_id );
    $is_valid_nonce = ( isset( $_POST[ 'video_nonce' ] ) && wp_verify_nonce( $_POST[ 'video_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
    
     // Exits script depending on save status
    if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
    return;
    }
    
    // Checks for input and sanitizes/saves if needed
     if( isset( $_POST[ 'eloado' ] ) ) {
    update_post_meta( $post_id, 'eloado', sanitize_text_field( $_POST[ 'eloado' ] ) );
     }
    if( isset( $_POST[ 'cim' ] ) ) {
    update_post_meta( $post_id, 'cim', sanitize_text_field( $_POST[ 'cim' ] ) );
    }
    }
    add_action( 'save_post', 'reggae_videodetails_save' );

    and use this code to show it on the site:

    <?php
        $meta_value = get_post_meta( get_the_ID(), 'honap', true );
        if( !empty( $meta_value ) ) {
            echo $meta_value;}
    		else
    ?>

    But I needed three of this meta boxes, because I wanted to add them for other custom type posts. So my functions.php has three of this code, every one of them has different names.

    Everything was working until now, my site freezes the computer again. I just added the get_post_meta tags and added some text to each meta box.

    This only happen in Google Chrome, I tested it in Mozilla Firefox and it worked without any freezing.

    I hope someone can help me with this because it’s really frustrating and I’d really like to use the custom meta boxes.

    Thanks for the answer.

Viewing 1 replies (of 1 total)
  • Thread Starter Valcsi

    (@valcsi)

    The problem got resolved. I found out that a font caused the freezing not the meta boxes.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom meta boxes causes computer freeze’ is closed to new replies.