Last active
March 10, 2024 20:56
-
-
Save SamuelHadsall/8e48c39b9a97466ccadf0cb971f5c273 to your computer and use it in GitHub Desktop.
Redirects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["agent"]=> string(37) "kirkwood-a-mrazek-moving-systems-u550" ["post_type"]=> string(5) "agent" ["name"]=> string(37) "kirkwood-a-mrazek-moving-systems-u550" | |
add_rewrite_rule( | |
'^movers/([^/-]+)/([^/-]+)/?$', | |
'index.php?post_type=agent&agent_actual_city=$matches[1]&name=$matches[2]', | |
'top' | |
); | |
if (is_singular('agent')) { | |
// Get the post ID | |
$post_id = $wp_query->get_queried_object_id(); | |
// Check if post ID is not empty | |
if ($post_id) { | |
// Get the correct city name | |
$city = $this->get_correct_city_name($post_id); | |
// Check if city is found | |
if ($city) { | |
// Add the city to the query vars | |
$wp_query->query_vars['agent_actual_city'] = $city; | |
} | |
} | |
// Load the template file | |
$template = plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'public/wp-templates/single-agent.php'; | |
// If the template file is found, load it | |
if ($template !== '') { | |
require_once $template; | |
exit; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function uni_add_custom_query_var( $qvars ){ | |
$qvars[] = 'agent_actual_city'; | |
$qvars[] = "state"; | |
$qvars[] = "city"; | |
$qvars[] = "agent_name"; | |
return $qvars; | |
} | |
function get_correct_city_name($post_id) { | |
// Check if the post type is "agent" | |
if (get_post_type($post_id) === 'agent') { | |
// Retrieve the city field value using ACF | |
$city = get_field('agent_actual_city', $post_id); | |
return $city; | |
} | |
// Return false if the post type is not "agent" | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment