Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Wordpress custom field input text translatable with qTranslate X?

I have some wordpress custom fields (I'm not using ACF or any other plugin for this) and need to translate them using qTranslate X in wp-admin.

The fields that I created with wp_editor are working, but I don't know how to make it work with default <input type="text"> for other custom fields that I have.

Below, a piece of code that I'm using to set variable and show my field:

    $services = isset( $values['services'] ) ? esc_attr( $values['services'][0] ) : '';
    wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<table>
    <tr>
        <td>
            <input type="text" name="services_title" value="<?php echo !empty($services_title) ? $services_title : ''; ?>" style="width: 100%" />
        </td>
    </tr>
</table>

then, I'm saving it with:

add_action( 'save_post', 'hotelSaveData' );
function hotelSaveData( $post_id )
{
    // Bail if we're doing an auto save
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    if (isset($_POST['services_title']))
        update_post_meta($post_id, 'services_title', wp_kses($_POST['services_title'], true));

}

Does anyone knows how to make it work, without using ACF or any other plugin ? (My fallback solution is to create another custom fields just to save other language data, but solve it with qTranslate would be great)

thanks =D

like image 827
Thiago Elias Avatar asked Jul 22 '15 17:07

Thiago Elias


1 Answers

Just use the inline syntax when adding the value on your input field e.g.

you can use this on input field value
[:en]Text Here for English Translation
[:de]Text Here for German Translation
[:es]Text Here for Spanish Translation[:] 

other inline syntax though I bet the input validator won't accept this tags
<!--:en-->English Text<!--:-->
<!--:de-->Deutsch<!--:-->

You can read more info from here https://qtranslatexteam.wordpress.com/faq/#CustomFields

like image 99
silver Avatar answered Oct 14 '22 04:10

silver