2017-11-04 8 views
0

ショートコード機能でdo_shortcodeを使用しようとしています。問題は、自分のページに[terms_and_conditions]を使用すると、do_shortcodeが解析されず、[MM_Form_Field type='custom' id='1' isRequired='true' class='']と表示されるということです。それは実行されていません。 ob_startが大幅にあなたのショートコードをクリーンアップすることができます使用do_shortcode内でショートコードを解析していません

function terms_and_conditions($atts) { 
    // Variables 
    $terms = get_field('terms_content', 'options'); 
    $checkbox = get_field('terms_checkbox_msg', 'options'); 
    // $smarttag = get_field('terms_smarttag', 'options'); 
    $smarttag = do_shortcode(get_field('terms_smarttag', 'options')); 

    var_dump($smarttag); 

    $html_out = ''; 

    $html_out .= '<section id="terms">'; 

     $html_out .= '<div class="terms-content-wrapper">'; 
      $html_out .= $terms; 
     $html_out .= '</div>'; // end terms-content-wrapper 

     $html_out .= '<div class="terms-checkbox-wrapper">'; 
      $html_out .= '<div class="terms-checkbox">'; 
       $html_out .= do_shortcode($smarttag); 
       $html_out .= '<p>' . $checkbox . '</p>'; 
      $html_out .= '</div>'; // end terms-checkbox 
     $html_out .= '</div>'; // end terms-content-wrapper 

    $html_out .= '</section>'; // end tip-wrapper 

    return $html_out; 
} 
add_shortcode('terms_and_conditions', 'terms_and_conditions'); 
+0

get_field( 'terms_smarttag'、 'options') 'は正確に何を返しますか?また、いくつかの奇妙なショートコードマジックをやっているのですか、do_shortcodeの戻り値にdo_shortcodeを間違って実行していますか? – janh

+0

@janh誰かが、このインスタンスでは 'do_shortcode'を二度実行する必要があると私に言った。私はそれも間違っていると思っていたし、私はそれを '$ html_out。= $ smarttag;'としていた。 'get_field'は[MM_Form_Field type = 'カスタム' id = '1' isRequired = 'true' class = '']を返します。 –

+0

'get_field( 'terms_smarttag'、 'options')'の内容は何ですか?私はdo-shortcodeを2回実行する必要はないと思います。 '[shortcode_a] [shortcode_b] [/ shortcode_a]' – admcfajn

答えて

0

これは私の関数は次のようになります。しかし、あなたはそれらを避けることを好むかもしれません。このの代わりに

[MM_Form_Field type="custom" id="1" isRequired="true" class=""] 

例えば、これを使用する:これは...

<?php 
function terms_and_conditions($atts) { 
    // Variables 
    $terms = get_field('terms_content', 'options'); 
    $checkbox = get_field('terms_checkbox_msg', 'options'); 
    $smarttag = get_field('terms_smarttag', 'options'); 

    ob_start(); 
    ?> 
    <section id="terms"> 
     <div class="terms-content-wrapper"> 
     <?php 
     if($terms){ 
      echo $terms; // <- is terms an array or a string? 
     } 
     ?> 
     </div> 
     <div class="terms-checkbox-wrapper"> 
      <div class="terms-checkbox"> 
       <?php 
       echo do_shortcode($smarttag); 
       if(!empty($checkbox)){ 
        echo '<p>' . $checkbox . '</p>'; // <- is checkbox an array or a string? 
       } 
       ?> 
      </div> 
     </div> 
    </section> 
    <?php 
    return ob_get_clean(); 
} 
add_shortcode('terms_and_conditions', 'terms_and_conditions'); 

あなたがあなたのショートコードで使用引用符を変更しているしようとする場合がありますもう一つの動作するはずです:

[MM_Form_Field type='custom' id='1' isRequired='true' class=''] 
関連する問題