2015-07-03 24 views
15

Pytanie zostało zaktualizowane. Poniżej znajduje się najnowsza wersja:Get_the_terms - wyświetla wszystkie typy wpisów:

Mam problemy ze zobaczeniem wszystkich typów postów podczas korzystania z niestandardowych postów. Jest to oparte na izotopach, a użytkownik powinien kliknąć linki, aby zobaczyć posty w tej kategorii.

Wyświetlane są wszystkie posty utworzone przez standardowe posty postów Wordpress, ale żadne nie zostały utworzone przy użyciu typów (postów niestandardowych).

<ul id="filters" class="whitetext whitelink myeluft"> 
    <li><a href="#" data-filter="*" class="selected">Alle</a></li> 
    <li><a href='#' data-filter='.foto'>Foto</a></li> 
    <li><a href='#' data-filter='.video'>Video</a></li> 
    <li><a href='#' data-filter='.web'>Web</a></li> 
</ul> 

<?php $the_query = new WP_Query('posts_per_page=50'); //Check the WP_Query docs to see how you can limit which posts to display ?> 
<?php if ($the_query->have_posts()) : ?> 
    <div id="isotope-list"> 
     <?php while ($the_query->have_posts()) : $the_query->the_post(); 


     // Query posts - post_types 
     $anypost = get_posts(array(
      'post_type'  => 'any' // every post type, but not attachments 
     )); 

     $termsArray = get_the_terms($post->ID, "category", $anypost); //Get the terms for this particular item 
     $termsString = ""; //initialize the string that will contain the terms 
      foreach ($termsArray as $term) { // for each term 
       $termsString .= $term->slug.' '; //create a string that has all the slugs 
      } 
     ?> 
     <div class="<?php echo $termsString; ?> item col-md-3"> <?php // 'item' is used as an identifier (see Setp 5, line 6) ?> 
      <h3><?php the_title(); ?></h3> 
       <?php if (has_post_thumbnail()) { 
          the_post_thumbnail(); 
        } ?> 
     </div> <!-- end item --> 
     <?php endwhile; ?> 
    </div> <!-- end isotope-list --> 
<?php endif; ?> 

Jak widzisz, próbowałem go naprawić, wstawiając poniższy kod, ale nadal nie pokazuje wszystkich typów wpisów.

// Query posts - post_types 
$anypost = get_posts(array(
    'post_type'  => 'any' // every post type, but not attachments 
)); 

$termsArray = get_the_terms($post->ID, "category", $anypost); //Get the terms for this particular item 

Czytałem this article, ale znalazłem mój własny więcej strat niż rozpoczął/

co byłoby rozwiązanie działa?

Aktualizacja

za pomocą następującego kodu jestem w stanie zobaczyć wszystkie posty, ale nie jest w stanie je odfiltrować. Patrz strona tutaj: http://goo.gl/e3cLuM (przewinąć w dół, aż zobaczysz wszystkie posty)

<?php $post_type = 'any'; 
$post_taxonomy = 'any'; 
// Get all 
$terms = get_terms($post_taxonomy); 

$portfolio = new WP_Query('post_type='.$post_type.'&post_per_page=-1'); ?> 
// First we loop our porfolio_category to show all categories as filter. 
<ul id="filters" class="whitetext whitelink myeluft"> 
    <a href="#" data-filter="*" class="selected"><li class="smoothtrans">Alle</li></a> 
    <a href='#' data-filter='.foto'><li class="smoothtrans">Foto</li></a> 
    <a href='#' data-filter='.video'><li class="smoothtrans">Video</li></a> 
    <a href='#' data-filter='.web'><li class="smoothtrans">Web</li></a> 
</ul> 

<?php if ($portfolio->have_posts()) : ?> 
       <div id="isotope-list"> 
        <?php while ($portfolio->have_posts()) : $portfolio->the_post(); 
// Get current post terms. 
         $item_terms = wp_get_post_terms(get_the_ID(), $post_taxonomy, $args); 
         $classes = ''; 
         // Append classes to use with each item. 
         foreach($item_terms as $item_term){ 
          $classes .= $item_term->slug.' '; 
         } 
         ?> 
         <div class="<?php echo $termsString; ?> item col-md-4"> 
          <ul class="grid cs-style-3"> 
           <li> 
            <figure> 
             <?php // 'item' is used as an identifier (see Setp 5, line 6) ?> 
             <?php if (has_post_thumbnail()) { 
               the_post_thumbnail(); 
             } ?> 
             <figcaption class="lefttext"> 
              <h3><?php the_title(); ?></h3> 
              <span class="offgrey">Nettside</span> 
              <a href="#" class="smoothtrans">Se prosjekt</a> 
             </figcaption> 
            </figure> 
           </li> 
          </ul>    
         </div> <!-- end item --> 
        <?php endwhile; ?> 
       </div> <!-- end isotope-list --> 
      <?php endif; ?> 
+0

używasz niestandardowej taksonomii do niestandardowego typu postu? –

+0

Dzięki za odpowiedź. To jest negatywne, ale byłoby możliwe dodanie taksonomii, jeśli jest to konieczne, aby działało. – Olen

+0

Czy próbowałeś tablica ("posts_per_page" => 50, "post_type" => any) dla WP_Query –

Odpowiedz

3

Problem został rozwiązany.

I wreszcie używany następujący kod:

<ul id="filters" class="whitetext whitelink myeluft"> 
     <a href="#" data-filter="*" class="selected"><li class="smoothtrans">Alle</li></a> 
     <a href='#' data-filter='.foto'><li class="smoothtrans">Foto</li></a> 
     <a href='#' data-filter='.video'><li class="smoothtrans">Video</li></a> 
     <a href='#' data-filter='.web'><li class="smoothtrans">Web</li></a> 
</ul> 

<?php 
$terms = get_terms($post_taxonomy); 

$args = array(
    'post_type' => 'any', 
    'posts_per_page' => 6, 
    'post_taxonomy' => 'any', 
); 

$the_query = new WP_Query($args); 


// Loop post_type 
?> 

<?php if ($the_query->have_posts()) : ?> 
    <div id="isotope-list"> 
     <?php while ($the_query->have_posts()) : $the_query->the_post(); 

     $termsArray = get_the_terms($post->ID, "category"); //Get the terms for this particular item 
     $termsString = ""; //initialize the string that will contain the terms 
      foreach ($termsArray as $term) { // for each term 
       $termsString .= $term->slug.' '; //create a string that has all the slugs 
      } 
     ?> 
     <div class="<?php echo $termsString; ?> item col-md-4"> 
      <ul class="grid cs-style-3"> 
       <li> 
        <figure> 
         <?php // 'item' is used as an identifier (see Setp 5, line 6) ?> 
         <?php if (has_post_thumbnail()) { 
           the_post_thumbnail(); 
         } ?> 
         <figcaption class="lefttext"> 
          <h3><?php the_title(); ?></h3> 
          <span class="offgrey"><?php echo(types_render_field("produkt", array('raw' => true))); ?>/<?php echo(types_render_field("produsert", array('raw' => true))); ?></span> 
          <a href="<?php the_permalink() ?>" rel="bookmark" class="smoothtrans">Se prosjekt</a> 
         </figcaption> 
        </figure> 
       </li> 
      </ul>    
     </div> <!-- end item --> 
     <?php endwhile; ?> 
    </div> <!-- end isotope-list --> 
    <script src="<?php bloginfo('stylesheet_directory'); ?>/js/toucheffects.js"></script> 
<?php endif; ?> 

nie było, że wiele zmian, co musiałem zrobić, ale było kilka.

Dziękuję wszystkim, którzy skomentowali i otrzymali działające pomysły.

Zauważ, że w kodzie nie ma jeszcze błędów, które nie zostały jeszcze naprawione.

0

any argument jest dla post_status, nie sądzę, że jest akceptowana przez post_type ('post_status' => 'any') (faktycznie, nie było prawidłowo wdrożone w niektórych wersjach)

można dać post_type tablicę z niektórymi typami zamiast:

'post_type' => array('post','page','event') 
+0

Dzięki za komentowanie. Przetestowałem to, ale wydawało się, że nie działa. Próbowałem również zastąpić tablice niestandardowymi wtyczkami pocztowymi, ale to też nie działało ... – Olen

+0

to sprawdź bazę danych i zobacz, co sprawia, że ​​te posty są różne (kategoria itp.). – FeedTheWeb

+0

Mam zaktualizowane pytanie. Jeśli chcesz, zobacz oryginalne pytanie. – Olen

4

Zakładając mamy zwyczaj rodzaj postu nazywa portfolio i niestandardowe taksonomii nazywa portfolio_category

<?php $post_type = 'portfolio'; 
$post_taxonomy = 'portfolio_category'; 
//First get all terms of portfolio_category. 
$terms = get_terms($post_taxonomy); 

$portfolio = new WP_Query('post_type='.$post_type.'&post_per_page=-1'); ?> 
// First we loop our porfolio_category to show all categories as filter. 
<ul id="filters" class="whitetext whitelink myeluft"> 
    <li><a href="#" data-filter="*" class="selected">All</a></li> 
    <?php foreach($terms as $term) : ?> 
     <li><a href='#' data-filter='.<?php echo $term->slug ?>'><?php echo $term->name ?></a></li> 
    <?php endforeach; ?> 
</ul> 

<?php if ($portfolio->have_posts()) : ?> 
       <div id="isotope-list"> 
        <?php while ($portfolio->have_posts()) : $portfolio->the_post(); 
// Get current post terms. 
         $item_terms = wp_get_post_terms(get_the_ID(), $post_taxonomy, $args); 
         $classes = ''; 
         // Append classes to use with each item. 
         foreach($item_terms as $item_term){ 
          $classes .= $item_term->slug.' '; 
         } 
         ?> 
         <div class="<?php echo $classes; ?> item col-md-3"> 
          <h3><?php the_title(); ?></h3> 
          <?php if (has_post_thumbnail()) { 
           the_post_thumbnail(); 
          } ?> 
         </div> <!-- end item --> 
        <?php endwhile; ?> 
       </div> <!-- end isotope-list --> 
      <?php endif; ?> 
+0

Dzięki. Wierzę, że coś tu jest. Dodałem post_taxonomy do postów w niestandardowym poście: Foto, i pojawił się. Jako taksonomię użyłem foto_category. Jednak lista w foreach, która będzie wyświetlać nazwy, nie działa poprawnie. Stronę znajdziesz tutaj: http://goo.gl/jytG7o (Przewiń w dół, aż zobaczysz Siste prosjekt). – Olen

+0

Przepraszam, myliłem się. Chodzi mi o to, że użyłem foto-kategorii jako ślimaka, a foto jako taksonomii. – Olen

+0

Mam zaktualizowane pytanie. Jeśli chcesz, zobacz oryginalne pytanie. – Olen