Sounds like you’re not seeing the posts in the category archive, if I’m following everything correctly.
I’d check out https://docs.pluginize.com/article/17-post-types-in-category-tag-archives which discusses this in a bit more detail, and also provides some code snippets to help get your post types into consideration for the category/tag archives.
Let me know if I’m not quite following correctly.
I try it, I put this code to function.php, but without results 🙁
code, what I put:
function my_cptui_add_post_types_to_archives( $query ) {
// We do not want unintended consequences.
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// Replace these slugs with the post types you want to include.
$cptui_post_types = array( 'recepty', 'Recepty' );
$query->set(
'post_type',
array_merge(
array( 'post' ),
$cptui_post_types
)
);
}
}
add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );
at in the end of function.php
For exaple:
My Post Type name is “Recepty”, it in chech recipes
https://sarahkopcanska.cz/kategorie/dezerty/ – it is category “Dezerty”
https://sarahkopcanska.cz/recepty/dynovka-2/ – its item in category “Dezerty” but it isn’t in the url …./kategorie/dezerty/
Is kategorie a custom taxonomy? or is it the default category from WordPress core, but also translated?
From what I’m seeing, it looks like a custom taxonomy.
If that’s the case, you’d want to make use of something like is_tax( 'kategorie' ); instead of is_category()
kategorie is my taxonomy, not default. It is category of recepty, its mean in Czech recipe
Try either is_tax( 'kategorie' ) and or is_tax( 'recepty' ) instead of what we had originally. Perhaps something like this:
if ( ( is_category() || is_tag() || is_tax( 'kategorie' ) || is_tax( 'recepty' ) ) && empty( $query->query_vars['suppress_filters'] ) ) {
This version will check if on a category archive OR tag archive OR kategorie archive OR recepty archive.
Oh! You are the best! Tnx! Its finally work! Thank You!
Welcome. Have a good rest of your day.