Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * If a single MyListing term is detected, load filtered "Explore listing" page instead of default archive template
- *
- * @param array $query The query object.
- * @param array $old_query The original query array.
- *
- * @return array The new query array is being returned if the explore_tab property is present. Otherwise, the original query is returned.
- */
- function bis_detect_archives( $query, $old_query ) {
- if ( function_exists( 'mylisting_custom_taxonomies' ) && empty( $_POST['submit_job'] ) ) {
- $explore_page_id = get_option( 'options_general_explore_listings_page', false );
- if ( empty( $explore_page_id ) ) {
- return $query;
- }
- $ml_query_vars = array(
- 'case27_job_listing_tags' => array(
- 'query_var' => 'explore_tag',
- 'tab' => 'tags'
- ),
- 'region' => array(
- 'query_var' => 'explore_region',
- 'tab' => 'regions'
- ),
- 'job_listing_category' => array(
- 'query_var' => 'explore_category',
- 'tab' => 'categories'
- )
- );
- $ml_taxonomies = mylisting_custom_taxonomies();
- if ( ! empty( $ml_taxonomies ) && is_array( $ml_taxonomies ) ) {
- $ml_taxonomies = array_keys( $ml_taxonomies );
- foreach ( $ml_taxonomies as $taxonomy ) {
- $ml_query_vars[ $taxonomy ] = array(
- 'query_var' => "explore_{$taxonomy}",
- 'tab' => $taxonomy
- );
- }
- }
- if ( ! empty( $query['taxonomy'] ) && in_array( $query['taxonomy'], array_keys( $ml_query_vars ) ) ) {
- $taxonomy_data = $ml_query_vars[ $query['taxonomy'] ];
- // 1. Set-up new query array variable
- $new_query = array(
- "page_id" => $explore_page_id,
- "explore_tab" => $taxonomy_data['tab'],
- $taxonomy_data['query_var'] => $query['term']
- );
- }
- }
- return ( ! empty( $new_query["explore_tab"] ) ) ? $new_query : $query;
- }
- add_filter( 'permalink_manager_filter_query', 'bis_detect_archives', 1, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement