Php 产品类别中的字母顺序分页
我试图在Woocommerce商店的主页上按字母顺序对类别进行分页,但它只在产品中有效,而不在类别中有效 下面是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()
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' );
在产品类别中工作需要更改哪些内容