• Hi,

    I have two custom post types:
    1) Resources (archive slug = resources, post slug = resource)
    2) Case Studies (archive slug = casestudies, post slug = casestudy).
    Resources has one custom taxonomy: Topics (archive slug = resources/[term])

    I have two questions regarding Custom Post Types and Taxonomies.

    Q1. How can I get the ‘prevpost’, ‘nextpost’ links to show below single custom posts (like they show up after single blog posts)?

    Q2. How can I show the custom taxonomy term below post title in the CPT archive and single custom post? (like the category is showing below the post title on blog archive and single post)

    I am not directly editing any of the core files of my setup (not that techie!), so just using the Code Snippets plugin as advised by you guys earlier.

    Would be super awesome if you can help me out here.

    Thanks and regards,
    Kads

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter kasin78

    (@kasin78)

    Hello again @diggeddy,

    Thanks for your prompt reply!

    I got the post navigation to work for both the CPTs, but I’m having trouble with showing the custom taxonomy term below the Post Title on my CPT archive page and single CPT.

    This is the code snippet I added:

    add_filter( 'generate_entry_meta_post_types', function( $types ) {
        $types[] = 'resources';
    
        return $types;
    } );

    My custom taxonomy slug is ‘topic‘.
    CPT archive URL is ‘https://www.lifepluspoint.com/resources/‘.
    Single CPT URL is of the form ‘https://www.lifepluspoint.com/resource/[post-slug/]‘.

    What am I doing wrong?
    ??

    • This reply was modified 3 years, 11 months ago by kasin78.

    Try the non-plural name:

    $types[] = 'resource';

    Thread Starter kasin78

    (@kasin78)

    Nope. That didnt work either. Not on the CPT archive page, not on the single CPT page.

    You think it might be creating a conflict coz of the slug rewrite?

    Ok let me remove the slug rewrite completely and try again with default settings. BRB.

    Thread Starter kasin78

    (@kasin78)

    Hey David,

    I removed the slug rewrites. So all custom post types and taxonomy pages are back to default slugs.

    CPT slug = resources
    tax slug = topic

    I used the original code with plural ‘resources’ in the snippet. Still doesnt work. ??

    If it’s any help, the following code was given to me here to display the Category meta on the Blog archive page & the single posts…

    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'categories',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            
        );
    } );

    What other information can I provide that might help?

    Thanks and regards,
    Kads

    Is the CPT set to use the wp Category Taxonomy ? Or it is using its own custom taxonomies ?

    Thread Starter kasin78

    (@kasin78)

    It wouldn’t show any posts in this CPT archive when I used the default Category with this CPT. I thought maybe we aren’t allowed to use the same taxonomy on two different post types. So I created a custom taxonomy, called Topics (slug=topic). It is associated with CPT Resources in the CPT UI plugin.

    [I’m new on WordPress… just learning along the way!]

    This topic explains how to include your own custom meta terms and then apply it to your posts:

    https://docs.generatepress.com/article/generate_header_entry_meta_items/

    Thread Starter kasin78

    (@kasin78)

    Thanks David, really appreciate your continued support on this.

    I couldn’t really understand where to enter the taxonomy slug and where its name, in the above code.

    This is what I have added:

    add_action( 'generate_post_meta_items', function( $item ) {
        if ( 'topic' === $item ) {
            echo 'Topics';
        }
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        $items[] = 'topic';
    
        return $items;
    } );

    It is simply showing the word ‘Topics’ now below the Post Titles, on both the CPT archive and single CPT, without the CSS I have given to show the Category.

    How do I get it to show the value of the taxonomy for each CPT post? And how do I apply the same CSS on the term?

    Thread Starter kasin78

    (@kasin78)

    Hello again @diggeddy,

    I tried to use the WP default Category again with this CPT (Resources). Here’s what happens:

    The Category names now show up fine on the Resources archive page and single CPTs, with the generate_header_entry_meta and generate_footer_meta codes.

    But no posts show up on the Category archive pages.
    Example:
    1) Resources archive – https://www.lifepluspoint.com/resources/ (WORKS FINE)
    2) Category archive – https://www.lifepluspoint.com/rrr/ (NO POSTS SHOW)

    So, is there some setting or code to manually enable the Category archive for CPTs? (I won’t need the custom taxonomy if this archive can work.)

    Regards,
    Kads

    Thread Starter kasin78

    (@kasin78)

    Okay I tried the code from this link – https://wordpress.stackexchange.com/questions/251939/why-are-posts-from-custom-post-type-not-displayed-in-category-archive

    Now the Category archives show up for my CPT!

    ??

    Thank you for nudging me in the right direction. All this while, I was under the impression that we cannot use default Category with CPTs!

    Many regards,
    Kads

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom Post Types and Taxonomies’ is closed to new replies.