Soporte » Plugins y Hacks » Metabox no actualiza en posts antiguos
Metabox no actualiza en posts antiguos
-
Buen día a toda la comunidad, he integrado unos metabox a mi sitio de wordpress de manera que pueda tener campos para agregar información personalizada. Todo funciona de maravilla, el problema es que únicamente surte efecto en los posts nuevos que vaya a crear, en cambio, en los posts que ya estaban creados, antes de la integración de mis metabox no surte efecto alguno, es decir, por más que coloco información en los campos y actualizo el post, no imprime el HTML en el Frontend.
Les dejo mi código que agregué en el archivo functions.php y espero su ayuda:
`function wpshed_get_custom_field( $value ) {
global $post;$custom_field = get_post_meta( $post->ID, $value, true );
if ( !empty( $custom_field ) )
return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );return false;
}function wpshed_add_custom_meta_box() {
add_meta_box( ‘wpshed-meta-box’, __( ‘Opciones de Reproductor’, ‘wpshed’ ), ‘wpshed_meta_box_output’, ‘post’, ‘normal’, ‘high’ );
add_meta_box( ‘wpshed-meta-box’, __( ‘Metabox Example’, ‘wpshed’ ), ‘wpshed_meta_box_output’, ‘page’, ‘normal’, ‘high’ );
}add_action( ‘add_meta_boxes’, ‘wpshed_add_custom_meta_box’ );
function wpshed_meta_box_output( $post ) {
// create a nonce field
wp_nonce_field( ‘my_wpshed_meta_box_nonce’, ‘wpshed_meta_box_nonce’ ); ?>
<div style=»display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;»>
<div style=»margin-right: 3%;»>
<p>
<label for=»wpshed_textarea_i»><?php _e( ‘Opción I’, ‘wpshed’ ); ?>:</label>
<textarea name=»wpshed_textarea_i» id=»wpshed_textarea_i» cols=»60″ rows=»4″><?php echo wpshed_get_custom_field( ‘wpshed_textarea_i’ ); ?></textarea>
</p>
<p>
<label for=»wpshed_textarea_iii»><?php _e( ‘Opción III’, ‘wpshed’ ); ?>:</label>
<textarea name=»wpshed_textarea_iii» id=»wpshed_textarea_iii» cols=»60″ rows=»4″><?php echo wpshed_get_custom_field( ‘wpshed_textarea_iii’ ); ?></textarea>
</p>
<p>
<label for=»wpshed_textarea_ii»><?php _e( ‘Opción II: (DESHABILITADO)’, ‘wpshed’ ); ?>:</label>
<textarea name=»wpshed_textarea_ii» id=»wpshed_textarea_ii» cols=»60″ rows=»4″ disabled><?php echo wpshed_get_custom_field( ‘wpshed_textarea_ii’ ); ?></textarea>
</p>
</div>
<div style=»-webkit-box-flex:1;-webkit-flex:auto;-ms-flex:auto;flex:auto;»>
<p>
<label for=»wpshed_fieldtext»><?php _e( ‘URL de Lista de Capítulos’, ‘wpshed’ ); ?>:</label>
<input type=»text» name=»wpshed_fieldtext» id=»wpshed_fieldtext» value=»<?php echo wpshed_get_custom_field( ‘wpshed_fieldtext’ ); ?>» style=»width: 100%;»>
</p>
<p>
<label for=»wpshed_download»><?php _e( ‘URL de Descarga’, ‘wpshed’ ); ?>:</label>
<input type=»text» name=»wpshed_download» id=»wpshed_download» value=»<?php echo wpshed_get_custom_field( ‘wpshed_download’ ); ?>» style=»width: 100%;»>
</p>
</div>
</div><?php
}function wpshed_meta_box_save( $post_id ) {
// Stop the script when doing autosave
if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return;// Verify the nonce. If insn’t there, stop the script
if( !isset( $_POST[‘wpshed_meta_box_nonce’] ) || !wp_verify_nonce( $_POST[‘wpshed_meta_box_nonce’], ‘my_wpshed_meta_box_nonce’ ) ) return;// Stop the script if the user does not have edit permissions
if( !current_user_can( ‘edit_post’, get_the_id() ) ) return;// Save the textarea I
if( isset( $_POST[‘wpshed_textarea_i’] ) )
update_post_meta( $post_id, ‘wpshed_textarea_i’, esc_attr( $_POST[‘wpshed_textarea_i’] ) );// Save the textarea II
if( isset( $_POST[‘wpshed_textarea_ii’] ) )
update_post_meta( $post_id, ‘wpshed_textarea_ii’, esc_attr( $_POST[‘wpshed_textarea_ii’] ) );// Save the textarea III
if( isset( $_POST[‘wpshed_textarea_iii’] ) )
update_post_meta( $post_id, ‘wpshed_textarea_iii’, esc_attr( $_POST[‘wpshed_textarea_iii’] ) );// Save the fieldtext
if( isset( $_POST[‘wpshed_fieldtext’] ) )
update_post_meta( $post_id, ‘wpshed_fieldtext’, esc_attr( $_POST[‘wpshed_fieldtext’] ) );// Save the URL download
if( isset( $_POST[‘wpshed_download’] ) )
update_post_meta( $post_id, ‘wpshed_download’, esc_attr( $_POST[‘wpshed_download’] ) );
}add_action( ‘save_post’, ‘wpshed_meta_box_save’ );
add_filter( ‘the_content’, ‘cyb_add_cutom_fields_to_content’ );
function cyb_add_cutom_fields_to_content( $content ) {
$custom_fields = get_post_custom();
if( isset( $custom_fields[‘wpshed_textarea_i’] ) && isset( $custom_fields[‘wpshed_textarea_ii’] ) && isset( $custom_fields[‘wpshed_textarea_iii’] ) && !empty($custom_fields[‘wpshed_textarea_i’][0]) && !empty($custom_fields[‘wpshed_textarea_iii’][0]) ) {
$content .= «<div class=’tabs__container’>
<ul class=’tabs__list’>- Opción I<svg viewBox=’0 0 73 68′ preserveAspectRatio=’xMinYMin meet’><path d=’M0 0v68.1h72.67c0 0-13.75-4.75-26.25-14.25S24.37 30.85 17.92 21C13.04 14.21 4.08 2 0 0z’></path></svg>
- Opción II<svg viewBox=’0 0 73 68′ preserveAspectRatio=’xMinYMin meet’><path d=’M0 0v68.1h72.67c0 0-13.75-4.75-26.25-14.25S24.37 30.85 17.92 21C13.04 14.21 4.08 2 0 0z’></path></svg>
- Opción III<svg viewBox=’0 0 73 68′ preserveAspectRatio=’xMinYMin meet’><path d=’M0 0v68.1h72.67c0 0-13.75-4.75-26.25-14.25S24.37 30.85 17.92 21C13.04 14.21 4.08 2 0 0z’></path></svg>
- Opción I<svg viewBox=’0 0 73 68′ preserveAspectRatio=’xMinYMin meet’><path d=’M0 0v68.1h72.67c0 0-13.75-4.75-26.25-14.25S24.37 30.85 17.92 21C13.04 14.21 4.08 2 0 0z’></path></svg>
- Opción II<svg viewBox=’0 0 73 68′ preserveAspectRatio=’xMinYMin meet’><path d=’M0 0v68.1h72.67c0 0-13.75-4.75-26.25-14.25S24.37 30.85 17.92 21C13.04 14.21 4.08 2 0 0z’></path></svg>
<div class=’tabs__body’>
<div class=’tab’ id=’opti’ style=’display: block;’>» . html_entity_decode($custom_fields[‘wpshed_textarea_i’][0]) . «</div>
<div class=’tab’ id=’optii’>contenido fijo estatico</div>
<div class=’tab’ id=’optiii’>» . html_entity_decode($custom_fields[‘wpshed_textarea_iii’][0]) . «</div>
</div>
</div>»;
} else if( isset( $custom_fields[‘wpshed_textarea_i’] ) && isset( $custom_fields[‘wpshed_textarea_ii’] ) && !empty($custom_fields[‘wpshed_textarea_i’][0]) ) {
$content .= «<div class=’tabs__container’>
<ul class=’tabs__list’><div class=’tabs__body’>
<div class=’tab’ id=’opti’ style=’display: block;’>» . html_entity_decode($custom_fields[‘wpshed_textarea_i’][0]) . «</div>
<div class=’tab’ id=’optii’>contenido fijo estatico</div>
</div>
</div>»;
}if( isset( $custom_fields[‘wpshed_fieldtext’] ) && !empty( $custom_fields[‘wpshed_fieldtext’][0] ) ) {
$content .= «Un texto cualquiera«;
}if( isset( $custom_fields[‘wpshed_download’] ) && !empty( $custom_fields[‘wpshed_download’][0] ) ) {
$content .= «<h1 style=’text-align:center;’>DOWNLAOD</h1>»;
}return $content;
}Espero su ayuda, gracias de antemano
- El debate ‘Metabox no actualiza en posts antiguos’ está cerrado a nuevas respuestas.