Die Frage wurde aktualisiert. Siehe unten für die neueste Version
Ich habe Probleme, alle Beitragstypen zu sehen, wenn ich benutzerdefinierte Beiträge verwende. Dies basiert auf Isotopen, und der Benutzer soll auf die Links klicken, um Beiträge in dieser Kategorie anzuzeigen.
Alle Posts, die von WordPress-Standardposts erstellt wurden, werden angezeigt, aber keine, die mit Types (Custom Posts) erstellt wurden.
<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; ?>
Wie Sie sehen, habe ich versucht, das Problem durch Einfügen des folgenden Codes zu beheben, aber es werden immer noch nicht alle Beitragstypen angezeigt.
// 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
ich habe gelesen Dieser Artikelaber ich fand mich selbst mehr verloren als angefangen /
Was wäre eine funktionierende Lösung?
Aktualisieren
Durch die Verwendung des folgenden Codes kann ich alle Beiträge sehen, aber nicht herausfiltern. Siehe Seite hier: http://goo.gl/e3cLuM (scrollen Sie nach unten, bis Sie alle Beiträge sehen)
<?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; ?>
Verwenden Sie eine benutzerdefinierte Taxonomie für Ihren benutzerdefinierten Beitragstyp?
– Touqeer Shafi
5. Juli 2015 um 10:24 Uhr
Danke für die Antwort. Das ist ein Nachteil, aber es wäre eine Möglichkeit, Taxonomie hinzuzufügen, wenn es notwendig ist, damit es funktioniert.
– Olen
5. Juli 2015 um 10:28 Uhr
Haben Sie versucht, array(‘posts_per_page’=>50,’post_type’=>any) für die WP_Query
– CᴴᵁᴮᴮʸNᴵᴺᴶᴬ
5. Juli 2015 um 10:30 Uhr
Ich glaube, dass irgendwo in diesem Code ein Syntaxfehler ist. Zumindest hat es nicht funktioniert.
– Olen
5. Juli 2015 um 10:39 Uhr
Auf welcher Vorlage genau steht das
– Pieter Goosen
5. Juli 2015 um 10:41 Uhr