• Resolved alexlbc

    (@alexlbc)


    Hello!
    If You can, I need help.

    My Web have plugin CPT UI, its really great, tnx.

    But category don’t work. I create content, and add category
    but it this post isn’t in category at website… but in admin panel it is – screen

    https://prnt.sc/11ri6r3

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter alexlbc

    (@alexlbc)

    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/

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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()

    Thread Starter alexlbc

    (@alexlbc)

    kategorie is my taxonomy, not default. It is category of recepty, its mean in Czech recipe

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter alexlbc

    (@alexlbc)

    Oh! You are the best! Tnx! Its finally work! Thank You!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome. Have a good rest of your day.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Help with category’ is closed to new replies.