• Buenos días,

    He creado mis metabox gracias a un tutorial http://cybmeta.com/como-crear-meta-boxes-y-campos-personalizados-custom-fields/) pero necesito poder traducir estos metabox con Qtranslate.

    Por un lado en functions.php tengo:

    <?php
    
    add_action('add_meta_boxes', 'cyb_meta_boxes');
    function cyb_meta_boxes() {
        add_meta_box( 'cyb-meta-box', __('Característiques'), 'cyb_meta_box_callback', 'post' );
    }
    function cyb_meta_box_callback( $post ) {
         wp_nonce_field( 'cyb_meta_box', 'cyb_meta_box_noncename' );
         $post_meta = get_post_custom($post->ID);
    
    				 //The input text 1: Any
    				 $current_value = '';
    				 if( isset( $post_meta['text_meta_any'][0] ) ) {
    					 $current_value = $post_meta['text_meta_any'][0];
    				 }
    				 ?>
    					<label class="label" for="text_meta_any"><?php _e("[Any"); ?></label>
    					<input  name="text_meta_any" id="text_meta_any" type="text" value="<?php echo $current_value; ?>">
    				 <?php
    }
    
    add_action('save_post', 'cyb_save_custom_fields');
    function cyb_save_custom_fields($post_id){
        // Primero comprobamos el tipo de post y que el usuario tenga permiso para editarlo
       if ( 'post' == $post->post_type || ! current_user_can( 'edit_post', $post_id ) ) {
            return;
        }
        // Segundo, comprobamos el nonce como medida de seguridad
    	if ( !isset( $_POST['cyb_meta_box_noncename'] ) || ! wp_verify_nonce( $_POST['cyb_meta_box_noncename'], 'cyb_meta_box' ) ) {
    		return;
    	}
       //Tercero, validamos y almacenamos el valor del custom field o lo borramos si es necesario
    
        //El text input 1: Any
    	if( isset($_POST['text_meta_any']) && $_POST['text_meta_any'] != "" ) {
                update_post_meta( $post_id, 'text_meta_any', sanitize_text_field( $_POST['text_meta_any'] ) );
    	} else {
                //$_POST['text_meta_any'] no tiene valor establecido, eliminar el meta field de la base de datos
    	    if ( isset( $post_id ) ) {
    	        delete_post_meta($post_id, 'text_meta_any');
    	    }
    	}
    }
    
    ?>

    y en la single.php tengo:

    <!-- Metabox -->
    			<?php
    				while ( have_posts() ) {
    					the_post();
    					$post_id = get_the_ID();
    					$text_meta_any = get_post_meta( $post_id, 'text_meta_any', true );
    			?>
    					<h2>
    						<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
    							<?php the_title(); ?>
    						</a>
    					</h2>
    				<p><?php the_content();?></p>
    				<ul class="metaBox">
    					<span class="metaSpan">Característiques</span>
    					<?php if( $text_meta_any != "" ) { ?><li>Any: <span><?php echo $text_meta_any; ?></span></li><?php } ?>
    
    				</ul>
    			<?php
    	}
    			?>
    		<!-- Metabox -->

    Como y donde añado los tags de Qtranslate? 🙁

    Gracias!!!

  • El debate ‘Metabox con Qtranslate’ está cerrado a nuevas respuestas.