2017-10-24 7 views
0

私は提供されたコードで試しましたが、動作しません... そしてそれはWordPress 4.8.2にアップデートした後にのみ問題を提起し始めました。 私はまた私はforeachとifを閉じるparteの後に... Wordpress 4.7.6で完璧に動作します... 任意のアイデア? ありがとうございました!WordPressの更新後にコードが機能しなくなった4.8.2

<?php 
     $cat_array = array(); 
     $args = array(
      'post_type' => 'post', 
      'posts_per_page' => 9, 
      'ignore_sticky_posts' => 1 
     ); 
     $my_query = null; 
     $my_query = new WP_Query($args); 

     if ($my_query->have_posts()) 
     { 
      while ($my_query->have_posts()): 
       $my_query->the_post(); 
       $cat_args = array(
        'orderby' => 'none' 
       ); 

       $cats = wp_get_post_terms($my_query->post->ID, 'category', $cat_args); 
       foreach($cats as $cat) 
       { 
        $cat_array[$cat->term_id] = $cat->term_id; 
       } 

      endwhile; 
      wp_reset_postdata(); 
     } 

     if ($cat_array) 
     { 
      foreach($cat_array as $cat) 
      { 
       $category = get_term_by('ID', $cat, 'category'); 
       $slug = get_term_link($category, 'category'); 
       $id = $category->term_id; 
       $valore = "category_" . $id; 
       $colore = get_field('colore_categoria', $valore); 
       $immagine = get_field('immagine_ispirazione', $valore); 
       $testo_box = get_field('testo_box', $valore); 


     ?> 

     <div class="colonna clearfix"> 
      <a href="<?php echo $slug;?>"> 
       <div class="box"> 
        <img src="<?php echo $immagine?>" alt="italia"> 
        <div class="overlay"> 
        <p><?php echo $testo_box;?></p> 
       </div> 
       <div class="titolobox" style="background-color:<?php echo $colore;?>"> 
        <h2><?php echo $category->name;?></h2> 
       </div> 
      </a> 
     </div> 

     </div> 

    <?php 
    } 


} 

wp_reset_query(); 
?> 

答えて

0

利用'ignore_sticky_posts'の代わり'caller_get_posts'this pageを参照してクエリを更新することができます

0

あなたの要件はわかりませんが、私はあなたがforeachループを閉じていないと思います。条件もあり、カテゴリの事前カスタムフィールド値が必要だと思いますあなたが使用するべきであるために投稿に割り当てられました

wp_get_post_categories(int $post_id, array $args = array()) 

whileループです。この助けを願う。

、あなたは "ignore_sticky_posts" ではなく "caller_get_posts"

0

使用怒鳴るコードを使用する必要があります。

<?php 
$cat_array = array(); 
$args = array(
    'post_type' => 'post', 
    'posts_per_page' => 9, 
    'ignore_sticky_posts' => 1 
); 
$my_query = null; 
$my_query = new WP_Query($args); 

if ($my_query->have_posts()) 
{ 
    while ($my_query->have_posts()): 
     $my_query->the_post(); 
     $cat_args = array(
      'orderby' => 'none' 
     ); 
     $cats = wp_get_post_terms($my_query->post->ID, 'category', $cat_args); 
     foreach($cats as $cat) 
     { 
      $cat_array[$cat->term_id] = $cat->term_id; 
     } 

    endwhile; 
    wp_reset_postdata(); 
} 

if ($cat_array) 
{ 
    foreach($cat_array as $cat) 
    { 
     $category = get_term_by('ID', $cat, 'category'); 
     $slug = get_term_link($category, 'category'); 
     $id = $category->term_id; 
     $valore = "category_" . $id; 
     $colore = get_field('colore_categoria', $valore); 
     $immagine = get_field('immagine_ispirazione', $valore); 
     $testo_box = get_field('testo_box', $valore); 
    } 
} 

?> 

はまだ働いていない

+0

を楽しむ:( –

関連する問題