Closed rmarcano closed 5 years ago
Please inform the customer of conversation # 348986 when this conversation has been closed.
FYI: I experienced this problem when trying to set the title for all categories of a custom post type, using the Yoast settings screen (Search Appearance > Taxonomies > MyCustomPostType > Title template*)
* I think, I am using the Dutch translation, so I am not sure the naming here is correct.
Note: Since Yoast 7.7, there is no error on the page anymore. However, the single/plural post type name is still not shown.
This is not a realistic way of using the %%pt_plural%%
or %%pt_singular%%
replacement variables.
A taxonomy can contain items from multiple post types, thus there is not one unique post type that applies.
The way to achieve what you are seeking for is to just hard-code the text that you want to have appear in front of the name of the taxonomy:
Hm, but I want to localize my text. This is not possible using the hard-coded approach.
I am using a custom taxonomy that is only used for a single post type.
Can't you tell if a taxonomy archive page is restricted to (child of) a single post type and echo the %%pt_plural%%
only then?
This was able up to major version 13, but from version 14 it is not able to put %%pt_single%%
or %%pt_plural%%
For some of our projects, it is an unhappy situation because we are prepending taxonomies which are connected only with one post type.
Is there any option on how to get post types works with taxonomies for title generating?
I am attaching screenshots where is Query Monitor debug for the main query.
We can see that for specific URL post type and taxonomy are recognized correctly by WordPress.
But WP SEO for this configuration can't recognize post type or taxonomy properly and the title is generated probably by default WordPress because we are using pipe |
in WP SEO config but dash -
is used for the title.
We are using this code to create URLs combination post-type and taxonomy
public static function addPostTaxonomiesRewrite($postType, $taxonomies)
{
$postTypeObject = \get_post_type_object($postType);
$taxonomiesObjects = array_map(function ($taxonomy) {
return \get_taxonomy($taxonomy);
}, $taxonomies);
$postTypeRewriteSlug = $postTypeObject->rewrite['slug'];
$taxonomiesRewriteSlugsString = join('/', array_map(function ($taxonomy) {
return $taxonomy->rewrite['slug'] . '/' . '(.+?)';
}, $taxonomiesObjects));
$taxonomiesRedirectString = join('&', array_map(function ($taxonomy, $i) {
$_i = $i + 1;
return "{$taxonomy}=\$matches[{$_i}]";
}, $taxonomies, array_keys($taxonomies)));
$regexPaged = "{$postTypeRewriteSlug}/{$taxonomiesRewriteSlugsString}/page/([0-9]{1,})?$";
$matchesIncrement = count($taxonomies) + 1;
$redirectPaged = "index.php?post_type={$postType}&{$taxonomiesRedirectString}&paged=\$matches[{$matchesIncrement}]";
\add_rewrite_rule($regexPaged, $redirectPaged, 'top');
$regex = "{$postTypeRewriteSlug}/{$taxonomiesRewriteSlugsString}/?$";
$redirect = "index.php?post_type={$postType}&{$taxonomiesRedirectString}";
\add_rewrite_rule($regex, $redirect, 'top');
}
Please give us a description of what happened.
Trying to use the %%pt_plural%% or %%pt_single%% template variable on a taxonomy archive results in the following error on the page:
Please describe what you expected to happen and why.
The post type label to be echoed on the page where I use the template variable.
How can we reproduce this behavior?
1.Edit a Category archive page to include the %%pt_plural%% in the title field for example.
2.Check the category page. See error.
Technical info