0
我已經建立了這個查詢在WordPress的找到一家公司的所有相關新聞:包括兩個類似wp_query在一個模板
<h2 class="heading">Related News</h2>
<?php $link = get_the_title(); ?>
<?php $portfolioloop = new WP_Query(array('post_type' => 'news')); ?>
<?php while ($portfolioloop->have_posts()) : $portfolioloop->the_post(); ?>
<?php $post_link = get_post_permalink(); ?>
<?php $post_title = get_the_title(); ?>
<?php if (get_field('featured_companies') != "") { ?>
<p style="margin:0px!IMPORTANT;">
<?php foreach(get_field('featured_companies') as $post): ?>
<?php $company = get_the_title(); ?>
<?php if ($company == $link) { ?>
<a href="<?php echo $post_link; ?>"><?php echo $post_title; ?></a><br />
<?php } ?>
<?php endforeach;?>
</p>
<?php } ?>
<?php endwhile; wp_reset_query(); ?>
我當時就想創造同樣的事情,但發現與相關聯的所有事件公司。即使新聞和事件的設置完全一樣,它似乎不工作,我錯過了什麼?
<h2 class="heading">Related Events</h2>
<?php $link_e = get_the_title(); ?>
<?php $portfolioloop_e = new WP_Query(array('post_type' => 'events')); ?>
<?php while ($portfolioloop_e->have_posts()) : $portfolioloop_e->the_post(); ?>
<?php $post_link_e = get_post_permalink(); ?>
<?php $post_title_e = get_the_title(); ?>
<?php if (get_field('featured_companies') != "") { ?>
<p style="margin:0px!IMPORTANT;">
<?php foreach(get_field('featured_companies') as $post_e): ?>
<?php $company_e = get_the_title(); ?>
<?php if ($company_e == $link_e) { ?>
<a href="<?php echo $post_link_e; ?>"><?php echo $post_title_e; ?></a><br />
<?php } ?>
<?php endforeach;?>
</p>
<?php } ?>
<?php endwhile; wp_reset_query(); ?>
我試過了wp_reset_query,但我沒有任何真正的線索該怎麼做!