douguadao3883 2013-04-04 13:27
浏览 36

WooCommerce:从所有产品中排除最近的产品

I want to show a number of recent products and than all other without those in recent.

I know that it's possible to do with posts in Wordpress by using 'offset' but I have no idea what to do with Woocommerce.

Any idea how to exclude first N products from all of them?

  • 写回答

1条回答 默认 最新

  • dps69208 2013-04-05 07:45
    关注

    you can modify the query via pre_get_posts and then simply set the offset.

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
        if ( ! $q->is_main_query() ) return;
        if ( ! $q->is_post_type_archive() ) return;
    
        if ( ! is_admin() ) {
            $q->set( 'offset', 5);
        }
    
        remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }
    

    (based on this snippet)

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序