带有排序选项的WordPress自定义分类后列表过滤器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有排序选项的WordPress自定义分类后列表过滤器相关的知识,希望对你有一定的参考价值。
// Get custom taxonomies // Get array of taxonomies eg activity, difficulty, subject // foreach taxonomy, get a list of options to sort by, terms, eg maths, science foreach ( $taxonomies as $tax => $tax_obj ){ $terms[$tax_obj->query_var] = get_terms($tax_obj->name); // array of terms } // check stuff in GET is a registered taxonomy foreach ( $_GET as $key => $val ){ // if its set, add an argument for get_posts if( $val ){ $tax_args[$key] = $val; } } } // build lines of conditions for if there are taxonomical requirements in the query string $sort_conditions = ''; $required_matches = -1; $sort_conditions.= " WHERE 0=1 "; // add this so other stuff can just repeat ORs foreach( $tax_args as $key => $slug ){ $sort_conditions.= " OR taxonomy = '$key' AND slug = '$slug' "; $required_matches ++; } } $sql =" SELECT count(1) AS matches,t1.* FROM( SELECT wp_posts.*, wp_term_taxonomy.taxonomy, wp_terms.slug FROM wp_posts LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_terms ON(wp_term_taxonomy.term_id = wp_terms.term_id) JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND wp_postmeta.meta_key = 'priority' AND wp_posts.post_status = 'publish' ORDER BY wp_postmeta.meta_value ASC, wp_posts.post_date DESC LIMIT 0, 999) AS t1 $sort_conditions GROUP BY ID HAVING matches > $required_matches"; $listing = $wpdb->get_results( $sql );
以上是关于带有排序选项的WordPress自定义分类后列表过滤器的主要内容,如果未能解决你的问题,请参考以下文章
PHP 带有自定义帖子类型和自定义分类的WordPress图库页面
带有中继器的嵌套选项卡 - 高级自定义字段 Wordpress
使用 Ajax 的带有自定义分类法的 Wordpress 多个自定义帖子类型过滤器 - 所有新创建的帖子都不会在响应中显示