Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 产品类别中的字母顺序分页_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 产品类别中的字母顺序分页

Php 产品类别中的字母顺序分页,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图在Woocommerce商店的主页上按字母顺序对类别进行分页,但它只在产品中有效,而不在类别中有效 下面是function.php中的代码: function os_restrict_by_first_letter( $where ) { if ( isset( $_GET['az'] ) ) { global $wpdb; if ( ! is_tag() && ! is_date() && is_archive()

我试图在Woocommerce商店的主页上按字母顺序对类别进行分页,但它只在产品中有效,而不在类别中有效

下面是
function.php
中的代码:

function os_restrict_by_first_letter( $where ) {
    if ( isset( $_GET['az'] ) ) {
        global $wpdb;
        if ( ! is_tag() && ! is_date() && is_archive() && is_main_query() ) {
            $where .= $wpdb->prepare( " AND SUBSTRING( {$wpdb->posts}.post_title, 1, 1 ) = %s ", sanitize_text_field( wp_unslash( $_GET['az'] ) ) );
        }
    }
    return $where;
}
add_filter( 'posts_where', 'os_restrict_by_first_letter' );
以下是
archive product.php
中的代码:

function os_restrict_by_first_letter( $where ) {
    if ( isset( $_GET['az'] ) ) {
        global $wpdb;
        if ( ! is_tag() && ! is_date() && is_archive() && is_main_query() ) {
            $where .= $wpdb->prepare( " AND SUBSTRING( {$wpdb->posts}.post_title, 1, 1 ) = %s ", sanitize_text_field( wp_unslash( $_GET['az'] ) ) );
        }
    }
    return $where;
}
add_filter( 'posts_where', 'os_restrict_by_first_letter' );

在产品类别中工作需要更改哪些内容