Wordpress WooCommerce-产品标题中的破折号打破了循环

Wordpress WooCommerce-产品标题中的破折号打破了循环,wordpress,woocommerce,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'

所以我运行这个查询:

// 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>';
}

请帮我理解

为什么要这样做:
$productObj=get_page_by_title(get_title(),OBJECT,'product')-您似乎想要获取产品的post对象,但您已经拥有了它。因为我不是Wordpress pro,不知道如何获取产品ID;)好吧,嗯,我不知道为什么,但解决了你提出的问题@AndyTschiersch把它都解决了:)现在只需要像这样简单地获取产品ID:
$productId=get_the_ID();
为什么这样做:
$productObj=get_page_by_title(get_title(),OBJECT,'product');
-您似乎想获取产品的post对象,但您已经拥有了。因为我不是Wordpress pro,也不知道如何获取产品ID;)好吧,嗯,我不知道为什么,但解决了您提出的@AndyTschiersch解决了所有问题:)现在只需像这样简单地获取产品ID:
$productId=get_the_ID()
<div class="author-entry__book-info">
<p class="title">Rogue &#8211; The Inside Story Of SARS&#8217;s Elite Crime-busting Unit</p>
</div>