2 pieces of similar PHP, one works one doesn't?

若如初见. 提交于 2019-12-24 16:44:13

问题


I've got a few fields on a property site, grabbing a value in English & depending on the value, translating it (if another language other than English is selected).

This piece of code works fine:

<?php if(get_post_meta($post->ID,'prop_parking',true) && $prop_parking):
    $prop_parking_meta = get_post_meta($post->ID,'prop_parking',true);
    if ($prop_parking_meta == 'Yes') {
        $prop_parking_meta = '<!--:en-->Yes<!--:--><!--:es-->Sí<!--:--><!--:ru-->да<!--:-->';
    }
    elseif ($prop_parking_meta == 'No') {
        $prop_parking_meta = '<!--:en-->No<!--:--><!--:es-->No<!--:--><!--:ru-->нет<!--:-->';
    } ?> 
         <li>
           <p><?php echo PROP_PARK_CSTM;?>:</p><p> <?php _e( $prop_parking_meta ); ?></p>
         </li>
<?php endif; ?>

I get back Yesin the set language, yet in this field I don't (I just see Yes or No):

<?php if(get_post_meta($post->ID,'prop_garage',true) && $prop_garage):
    $prop_garage_meta = get_post_meta($post->ID,'prop_garage',true);
    if ($prop_garage_meta == 'Yes') {
        $prop_garage_meta = '<!--:en-->Yes<!--:--><!--:es-->Sí<!--:--><!--:ru-->да<!--:-->';
    }
    elseif ($prop_garage_meta == 'No') {
        $prop_garage_meta = '<!--:en-->No<!--:--><!--:es-->No<!--:--><!--:ru-->нет<!--:-->';
    } ?>        
          <li>
           <p><?php echo PROP_GARG_CSTM;?>:</p><p> <?php _e( $prop_garage_meta ); ?></p>
          </li>
<?php endif; ?>

Is it something obvious I'm missing? :( Thanks!


回答1:


I don't know why this issue happens sometimes in qTranslate, but there are two options to deal with it:

  1. using the shortcode notation

    $prop_garage_meta = '[:en]Yes[:es]Sí[:ru]да';
    
  2. applying the_content filter

    $prop_garage_meta = apply_filters( 
        'the_content', 
        '<!--:en-->Yes<!--:--><!--:es-->Sí<!--:--><!--:ru-->да<!--:-->' 
    );
    


来源:https://stackoverflow.com/questions/23866214/2-pieces-of-similar-php-one-works-one-doesnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!