dongzhuo6137 2016-08-15 06:15
浏览 87
已采纳

隐藏缺货 - “pre_get_posts”分类标识,以便在商店页面上显示

In my WooCommerce store, I have "Hide out of stock items from the catalogue" enabled. This option causes product variations on individual pages to become invisible.

I want to apply "Hide out of stock items from the catalogue" option only on archive pages (search, categories).

Here is my code:

function featured_posts( $query ) {
    if ( ! $query->is_main_query() ) return;

    //What goes in here?
}
add_action( 'pre_get_posts', 'featured_posts' );

How can I achieve this?

Thanks

  • 写回答

1条回答 默认 最新

  • duan205571 2016-08-15 06:25
    关注

    Try This

    You have to check page for do this as follow

    function featured_posts( $query ) {
    
        if(is_product_category() || is_search()){
            if ( ! $query->is_main_query() ){
                return;
            }
        }
        ....
    }
    add_action( 'pre_get_posts', 'featured_posts' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题