第一个循环中的代码:
<?php
$terms_as_text = get_the_term_list( $post->ID, 'produktkategori', '', ', ', '' ) ;
echo strip_tags($terms_as_text);
?>
“Spanskt”的结果。我希望在第二个循环中输入“Spanskt”,它表示“Spanskt”。那可能吗?
提前致谢。
// First loop
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php
$terms_as_text = get_the_term_list( $post->ID, 'produktkategori', '', ', ', '' ) ;
echo strip_tags($terms_as_text);
?> // The value of this...</h1>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
Some content
</article>
<?php endwhile; endif; ?>
// Second loop
<?php $loop = new WP_Query( array( 'post_type' => 'bocker', 'posts_per_page' => 4, 'produktkategori' => 'Spanskt // ...should be entered here', 'orderby' => 'rand', ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
Some content
<?php endwhile; ?>
答案 0 :(得分:0)
这是我的解决方案:
// First loop
<?php $loop = new WP_Query( array( 'post_type' => 'forfattare', 'posts_per_page' => 10, 'orderby' => 'title', 'order' => 'ASC' ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $string = get_the_title() ;
$forfattare = createAlias( $string );
?>
// Second loop
<?php $loop_2 = new WP_Query( array( 'post_type' => 'bocker', 'posts_per_page' => 10, 'forfattare' => ''.$forfattare.'', 'orderby' => 'rand', 'order' => 'ASC', ) ); ?>
<?php while ( $loop_2->have_posts() ) : $loop_2->the_post(); ?>
<div class="italic"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<?php endwhile; ?>
<?php endwhile; ?>