Home › Forums › Front-end Issues › Meta Title Incorrect for a Custom Permalink Structure
By redirecting a 404 page, we were able to get a custom permalink structure with /%service%/%area%/listingname to work with ACF custom posts. Everything is correct except ONE item… the Meta Title displays the title of the latest blog post.
I can’t figure out how to fix this. I’ve included the code for the custom permalink structure below. Can someone provide some insight to getting the title to be correct?
add_action('template_redirect', 'flex_advanced_cpt_permalink_structure');
function flex_advanced_cpt_permalink_structure()
{
if (is_404()) {
global $wp_query;
$service_index = 1;
$area_index = 2;
$service_tax = "services";
$area_tax = "areas";
$post_type = 'listing';
$url = array_filter(explode('/', $_SERVER['REQUEST_URI']));
if (count($url) == 1) {
if (term_exists($url[$service_index], $service_tax)) {
$wp_query = new WP_Query(array(
'post_type' => $post_type,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $service_tax,
'field' => 'slug',
'terms' => $url[$service_index],
),
),
));
status_header(200);
include('/public_html/wp-content/themes/genesis/index.php');
exit();
}else if(term_exists($url[$service_index], $area_tax)){
$wp_query = new WP_Query(array(
'post_type' => $post_type,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $area_tax,
'field' => 'slug',
'terms' => $url[$service_index],
),
),
));
status_header(200);
include('/public_html/wp-content/themes/genesis/index.php');
exit();
}
} else if ((count($url) == 2)) {
if (term_exists($url[$service_index], $service_tax) && term_exists($url[$area_index], $area_tax)) {
$wp_query = new WP_Query(array(
'post_type' => $post_type,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $service_tax,
'field' => 'slug',
'terms' => $url[$service_index],
),
array(
'taxonomy' => $area_tax,
'field' => 'slug',
'terms' => $url[$area_index],
),
),
));
status_header(200);
include('/public_html/wp-content/themes/genesis/index.php');
exit();
}
} else if (count($url) == 3) {
if (term_exists($url[$service_index], $service_tax) && term_exists($url[$area_index], $area_tax)) {
$wp_query = new WP_Query(array(
'post_type' => $post_type,
'name' => $url[3],
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $service_tax,
'field' => 'slug',
'terms' => $url[$service_index],
),
array(
'taxonomy' => $area_tax,
'field' => 'slug',
'terms' => $url[$area_index],
),
),
));
status_header(200);
include('/public_html/wp-content/themes/dynamik-gen/single-listing.php');
exit();
}
}
}
}
add_filter('post_type_link', 'pleasure_post_links', 99, 2);
function pleasure_post_links($permalink, $post)
{
if ($post->post_type == "listing") {
$service = wp_get_post_terms($post->ID, 'services');
$area = wp_get_post_terms($post->ID, 'areas');
$permalink = get_bloginfo('url') . '/' . $service[0]->slug . '/' . $area[0]->slug . '/' . $post->post_name;
return $permalink;
}
return $permalink;
Spoke some more with the developer that wrote the code.
He believes it might be something related to the Genesis Theme.
The topic ‘Meta Title Incorrect for a Custom Permalink Structure’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.