WooCommerce - 产品标题中断的循环

时间:2017-02-17 08:51:10

标签: wordpress woocommerce

所以我正在运行此查询:

// find books that have this author
$author_name = get_the_title();                     

// args
$booksby_args = array(
    'post_type'      => 'product',
    'post_status'    => 'any',
    'posts_per_page' => -1,
    'orderby'        => 'title',
    'order'          => 'ASC',
     'tax_query'     => array(
         array( 
          'taxonomy' => 'pa_author-woo',
          'terms'    => $author_name, 
          'field'    => 'name'
         ), 
      ), 
);

// The Query
$thebooks_query = new WP_Query( $booksby_args );

// The Loop
if ( $thebooks_query->have_posts() ) {
  echo '<h3>Books by '.$author_name.'</h3>';
  echo '<ul class="author-entry__book-list">';
  while ( $thebooks_query->have_posts() ) {
    $thebooks_query->the_post();

    $productObj       = get_page_by_title( get_the_title(), OBJECT, 'product' );
    $productId        = $productObj->ID;        
    $wc_product       = wc_get_product( $productId );                       

    echo '<li class="clearfix">'; 
    echo '<a href="'.get_permalink( $productId ).'">';
    echo the_post_thumbnail('shop_thumbnail');
    echo '<div class="author-entry__book-info">';
    echo '<p class="title">'.get_the_title().'</p>';                          
    echo '<p class="price">'.$wc_product->get_price_html().'</p>';
    echo '</div>';
    echo '</a>';
    echo '</li>';
  }
  echo '</ul>';
}

但是,只要产品的标题包含&#39; - &#39;,在输出标题后,输出似乎就会失败。甚至没有空<p class="price">标签。在我的模板下面的其他元素也不会被输出。

另外,如果我尝试定义价格的变量,例如在所有echo语句之前$wc_price = $wc_product->get_price_html(),根本没有渲染回声!

如果我评论价格回音或产品标题不包含短划线,那么一切正常。

这是失败后输出内容的片段:

<div class="author-entry__book-info">
<p class="title">Rogue &#8211; The Inside Story Of SARS&#8217;s Elite Crime-busting Unit</p>
</div>

请帮助我理解!

0 个答案:

没有答案
相关问题