Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_detect_archives($request) {
- global $wp, $wpdb;
- $post_types = array(
- 'events' => 'events'
- );
- $taxonomies = array(
- 'solutions'
- );
- // Parse the URI (name_of_post_type/taxonomy_term)
- preg_match('/([^\/]+)\/([^\/]+)(?:\/page\/([\d]+))?/', $wp->request, $parts);
- if(!empty($parts[1]) && !empty($post_types[$parts[1]])) {
- // Get post type
- $post_type = $post_types[$parts[1]];
- // Get term
- $term = $wpdb->get_row($wpdb->prepare("
- SELECT * FROM {$wpdb->terms}
- LEFT JOIN {$wpdb->term_taxonomy} ON {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id
- WHERE slug = %s",
- sanitize_title($parts[2])
- ));
- // Filter the query if both post type & term were found
- if(!empty($term) && in_array($term->taxonomy, $taxonomies)) {
- $request = array(
- 'post_type' => $post_type,
- 'taxonomy' => $term->taxonomy,
- 'term' => $term->slug,
- 'do_not_redirect' => 1,
- );
- // Suport pagination
- if(!empty($parts[2])) {
- $request['paged'] = $parts[2];
- }
- }
- }
- return $request;
- }
- add_filter('request', 'pm_detect_archives', 99);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement