簡體   English   中英

Wordpress中具有自定義分類的自定義帖子循環

[英]Custom post loop with custom taxonomy in wordpress

我在某處出錯,這使我發瘋。 我試圖從具有自定義分類法的自定義帖子類型中提取帖子。 我通過URL中的ID提取分類法,無論我做什么,它似乎都顯示該帖子類型的所有帖子。 這是我的代碼:

<?php
                                $cruise = $_GET['reederei'];
                                $info = get_term_by( 'slug', $cruise, 'reederei' );
                                $info_id = $info->term_id;
$logo = get_field('logo', $term);

                        foreach ($taxes as $tax) {
    $the_taxes[] = array (  
        'taxonomy' => 'reederei',
        'field'    => 'term_id',
        'terms'    => 'array( $info_id)',
    );
}

$the_taxes['relation'] = 'OR';

$query = new WP_Query( array(
    'post_type' => 'angebote',
    'tax_query' => $the_taxes,
) );

  if ( $query->have_posts() ) : ?>
    <?php while ( $query->have_posts() ) : $query->the_post(); ?>   
        <div class="col-sm-4">
            <div class="offer_box_container offer_main">
            <div class="offer_box_thumbnail"><a href="<?php the_permalink(); ?>" target="_top"><img src="<?php the_field('featured_image'); ?>"/></a></div>
            <h2 class="offer_inner_title"><a href="<?php the_permalink(); ?>" target="_top"><?php the_title(); ?></a></h2>
            <div class="offer_inner_sub highlight"><?php the_field('number_of_nights'); ?> Nächte: <?php the_field('travelling_to'); ?></div>
            <div class="offer_description"><?php echo custom_field_excerpt(); ?></div>
            <div class="col-sm-7 offer_button"><a class="direct_button" href="<?php the_permalink(); ?>" target="_blank">Zum Angebot &gt;&gt;&gt;</a></div>
            <div class="col-sm-5"><div class="before_price">pro Person ab</div>
                                    <div class="main_price"><?php the_field('price'); ?> -</div></div>
                                </div>
        </div>
    <?php endwhile; wp_reset_postdata(); ?>
<!-- show pagination here -->
<?php else : ?>
    <!-- show 404 error here -->
<?php endif; ?>
 $the_taxes[] = array (  
    'taxonomy' => 'reederei',
    'field'    => 'term_id',
    'terms'    => 'array( $info_id)',
);

您將'terms'=> array()轉換為字符串。 看看是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM