Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter lzanoni

    (@lzanoni)

    Yup, prefixing with a “_” does the trick ??
    Do you know why there is a difference in behaviour without the _ ?

    Thread Starter lzanoni

    (@lzanoni)

    Hum… as an unpractical workaround, I’ve added a dummy language ‘Original’ also set to ‘en_US’ (with a different slug), and made it the ‘Original language’ in SL, but the drawback is that now I have to add a “translation” for English too. But now, I have working custom fields for all languages.

    Thread Starter lzanoni

    (@lzanoni)

    I changed the Default and original language in Sublanguage’s settings to French, and now the French translation lost its custom fields in the editor, so probably connected to the ‘Main’ language of the post.

    I’m probably making something wrong…

    Thread Starter lzanoni

    (@lzanoni)

    Hello again Maxime, I implemented also the code to save the custom fields. Now the custom fields work for all translations, except in the original English: the custom metabox values are always empty.
    I also tried creating a new page in English (in case something was broken on my existing page), edit my custom fields, then switch to French and edit the custom fields: same result: the custom are OK for french, but not for English.

    Here is my functions.php:

    <?php
    
    add_filter('sublanguage_register_postmeta_key','my_translate_postmeta');
    function my_translate_postmeta($postmeta_keys)
    {
      array_push($postmeta_keys,"page_id","use_toc","title","title_image","side_text","side_image");
      return $postmeta_keys;
    }
    
    add_action('add_meta_boxes','my_add_meta_boxes');
    add_action('save_post','my_save_post');
    
    function my_add_meta_boxes($post)
    {
      add_meta_box('metabox','Custom values','my_add_meta_box_content','page','normal','high');
    }
    function my_add_meta_box_content($post)
    {
      echo "<table>\n";
      $keys=my_translate_postmeta(array());
      foreach($keys as $k)
      {
        echo "<tr><td><label>$k:</label></td><td><input type='text' name='metabox_$k' value='".get_post_meta($post->ID,$k,true)."'/></td></tr>";
      }
      echo "</table>\n";
    }
    
    function my_save_post()
    {
    	global $post;
    	if($_POST)
    	{
    	  $keys=array();
    	  $keys=my_translate_postmeta($keys);
    	  foreach($keys as $k)
    	  {
    	    if(isset($_POST['metabox_'.$k]))
    	    {
    	      $meta=esc_attr($_POST['metabox_'.$k]);
    	      update_post_meta($post->ID,$k,$meta);
    	    }
    	  }
    	}
    }
    Thread Starter lzanoni

    (@lzanoni)

    Hello Maxime, thanks for the quick reply.

    Unfortunately, my WP knowledge is minimal.

    I’ve added your snippet in my theme ‘functions.php’, and added a custom meta box (actually a table with the 6 input fields I need).
    The problem is how do I link this metabox with Sublanguage ? How can I make the magic operate ?? ? The $post->ID I get in the add_meta_box callback is the original one, not the translated one.

Viewing 5 replies - 1 through 5 (of 5 total)