【问题标题】:Wordpress/Woocommerce post was called incorrectlyWordpress/Woocommerce 帖子被错误调用
【发布时间】:2017-10-04 11:33:00
【问题描述】:

我修复了除一个之外的所有 woocommerce 已弃用的功能,也许有人可以帮助我。我不是专业人士。谢谢。

唯一激活的插件是 woocommerce,因此不存在插件冲突问题。wordpress 是最新的,woocommerce 也是。

我收到此通知,据我所知,问题来自 page.php

Notice: post was called incorrectly. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/barbuto/page.php'), WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /home/public_html/dev/wp-includes/functions.php on line 4139

这是 page.php 文件中的代码。

get_header(); ?>

<?php if(is_front_page()){ ?>

<!-- start of banner -->
        <div class="banner" style="background: url('<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>') no-repeat scroll center center transparent;">  
        </div>
<!-- end of banner -->

<div class="wrapper">
<ul class="products">
    <?php
        $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'meta_key' => '_featured', 'meta_value' => 'yes',  );
        $loop = new WP_Query( $args );
        echo "<h1>"; count($loop); echo "</h1>";
        $i=1;
        while ( $loop->have_posts() ) : $loop->the_post(); global $product;  global $woocommerce; ?>

        <div class="product_featured_img <?php echo $loop->post->ID; ?> <?php if(($loop->post->ID == '405') || ($loop->post->ID == '72')){ echo 'bottol';} ?>">
            <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
            <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
            <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'large'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder"  />'; ?>
              </a>
        </div>
    <div class="bottol_text product_featured_content">
        <h3>
        <a href="<?php echo get_permalink( $loop->post->ID ) ?>" 
        title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
            <?php the_title(); ?>
        </a>        
        </h3>

        <p>
        <?php 
        //$text_length = count($product->post->post_content);
        //if($text_length > 1000){
        //  echo substr($product->post->post_content,0,2000).'...';
                          /*}  else { */
        echo $product->post->post_content;  
        //} 
        ?> 
        </p>

         <?php if ( is_user_logged_in() ) {  ?> 
         <p class="price"><?php echo $product->get_price_html(); ?></p> 
         <div class="add_box">
         <a class="add_to_cart_button button product_type_simple" data-product_sku="<?php echo $product->get_sku(); ?>" data-product_id="<?php echo $loop->post->ID;?>" rel="nofollow" href="<?php  echo $product->add_to_cart_url(); ?>" > add to cart </a>
         </div>
         <?php }else{echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('PLEASE LOGIN/REGISTER TO VIEW PRICES', 'theme_name') . '</a>';}?>

    </div>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul><!--/.products-->      
    </div>  

【问题讨论】:

  • 如果你暂时去掉这行:echo $product-&gt;post-&gt;post_content; 通知会消失吗?
  • @Und3rTow nop ,但我通过更改此行来修复它 echo $product->post->post_content;到这一行 echo $loop->post->post_content; ,所以我写了 $product 的安装 $loop 并且它接缝正在工作。谢谢你

标签: php wordpress


【解决方案1】:

将这一行 echo $product-&gt;post-&gt;post_content;
替换为
echo $loop-&gt;post-&gt;post_content;

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2018-03-23
    • 1970-01-01
    • 2014-04-26
    相关资源
    最近更新 更多