wordpress帖子通过帖子标签过滤标签

时间:2017-08-23 06:23:03

标签: php jquery wordpress

我正在为特定类别中的每个代码添加过滤器,并使用以下代码获取所有代码现在我正在为此系统添加标签,anchor标签在echo

中不起作用
  <?php
$dyno_cat = get_field( "category_slug" );
        $query_args = array(
          'category_name' => $dyno_cat,
          'posts_per_page' => -1
        );

        $query = new WP_Query( $query_args );
        $posttags = "";
        while( $query->have_posts() ) {
          $query->the_post();
            if( get_the_tag_list() ){
              $posttags = $posttags . get_the_tag_list('',',',',');
            }
        }
        // Reset
        wp_reset_postdata();
        // Explode tags in array
        $sortedtags = explode(',', $posttags);
        // Sort array
        asort($sortedtags);
        // Remove duplicates from array
        $sortedtags = array_unique($sortedtags);
        // Remove the blank entry due to get_the_tag_list
        $sortedtags = array_values( array_filter($sortedtags) );
        // Wrap each tag in list element
        echo '<ul class="nav nav-tabs" role="tablist">';
        foreach ($sortedtags as $tagname) {
          //echo '<li>' . $tagname . '</li>';
           echo 
            '<li>
                <a href="#'.$tagname.'" role="tab" data-toggle="tab">    
                    '.$tagname.'
                </a>
            </li>';
        }
        echo '</ul>';
        echo '<div class="tab-content">';
        foreach($sortedtags as $tagname) { 
            echo '<div class="tab-pane" id="' . $tagname.'">';

            $the_query = new WP_Query(array(
                'post_status'   => array('private'),
                'posts_per_page' => -1,
                'category_name' => $dyno_cat
            ));

            while ( $the_query->have_posts() ) : 
            $the_query->the_post();
            echo '<h1>';
                the_title();
            echo '</h1>';
            endwhile; 
        } 
        echo '</div>';

      ?>  

似乎帖子越来越多,但标签不起作用,请查看附加的屏幕enter image description here

$tagname the tag name coming some thing like with below format ,

<a href=" http:="" top100-elite-traveler.pantheonsite.io="" tag="" americas"="" rel="tag">Americas</a>

0 个答案:

没有答案