Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Rewrite listing taxonomy permalinks (if custom landing page selected)
- **/
- function pm_rewrite_listing_tax_permalinks($link, $term, $taxonomy) {
- if(strpos($taxonomy, 'job_listing') !== false && function_exists('get_field')) {
- // A. Use "Custom Landing Page" ACF field
- $region_page = get_field('_landing_page', $term->taxonomy . '_' . $term->term_id);
- // Change the term permalink to page permalink
- if(!empty($region_page->ID)) {
- $region_page_link = get_permalink($region_page->ID);
- }
- }
- return (!empty($region_page_link)) ? $region_page_link : $link;
- }
- add_filter('term_link', 'pm_rewrite_listing_tax_permalinks', 1000, 3);
- /**
- * Redirect listing category permalinks (if custom landing page selected)
- **/
- function pm_redirect_listing_tax_permalinks($query, $old_query, $uri_parts, $pm_query, $content_type) {
- if(!empty($pm_query['id']) && strpos($content_type, 'job_listing') !== false && strpos($content_type, 'Taxonomy:') !== false && function_exists('get_field')) {
- $taxonomy = preg_replace('/(.+?)([\S]+)$/i', '$2', $content_type);
- $term_id = preg_replace('/(tax-)([\S]+)$/i', '$2', $pm_query['id']);
- $region_page = get_field('_landing_page', $taxonomy . '_' . $term_id);
- // If custom landing page is set trigger the redirect from term URL
- if(!empty($region_page)) {
- $region_page_link = get_permalink($region_page->ID);
- if($region_page_link) {
- wp_safe_redirect($region_page_link, 301);
- exit();
- }
- }
- }
- return $query;
- }
- add_filter('permalink_manager_filter_query', 'pm_redirect_listing_tax_permalinks', 3, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement