Hallo Community,
für ein Wordpress-Template entwickel ich gerade ein Widget, dass ein paar Customs-Posts aus einer bestimmten Kategorie ausgeben soll. Das ermittel der Kategorie und der Zugriff auf dessen Daten funktioniert porblemlos. Aber das WP_Query, dass ich eingebaut habe, liefert immer ein leeres Result und ich weiß leider nicht warum.
Folgend mein Aktueller Widget-Code:
PHP
<?php
//...
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$product_category_id = $instance['product_category_id'];
if ( $product_category_id > -1 ) {
$category = get_term($product_category_id, 'product_categories');
}
if ( $category ) {
echo $before_widget;
echo '<div class="widget hk_product_category_widget">';
// Check if title is set
if ( $title ) {
echo $before_title . $title . $after_title;
} else {
echo $before_title . $category->name . $after_title;
}
echo '<div class="widget_content">';
$query = new WP_Query(
array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_categories',
'field' => 'term_id',
'terms' => array( $category->term_id )
),
),
'orderby' => 'post_date',
'order' => 'DESC',
'posts_per_page' => 9,
'post_status' => 'publish'
)
);
echo '<pre>';
var_dump($query->posts);
echo '</pre>';
while ( $query->have_posts() ) : $query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile;
echo '</div>';
echo '</div>';
echo $after_widget;
}
}
//...
?>
Alles anzeigen
Wie gesagt, aus einem mir unbekannten Grund liefert das Query keine Ergebnisse, obwohl ca. 170 Produkte dieser Kategorie zugeordnet sind.
Hat jemand von euch eine Idee was ich falsch mache? Würde mich über ein paar Antworten freuen.
MfG Kinger