Site logo

[Resolved] Post meta & Category / Tags does not display for custom post type

Home Forums Support [Resolved] Post meta & Category / Tags does not display for custom post type

Home Forums Support Post meta & Category / Tags does not display for custom post type

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #661382
    Laurent

    Hi,

    Thanks for the theme it’s really great.

    I’m using custom post types that I allow to be displayed on the blog use a filter on pre_get_posts. That works, I can see my custom post types.

    However, even though I have set “display category / tags / date” in theme customization, they don’t appear.

    Do I have to do something ?

    Thanks

    #661738
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try these functions:

    add_action( 'generate_after_entry_title', function() {
        $post_types = array(
            'one-post-type',
            'another-post-type',
        );
    
        if ( in_array( get_post_type(), $post_types ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    } );
    
    add_action( 'generate_after_entry_content', function() {
        $post_types = array(
            'one-post-type',
            'another-post-type',
        );
    
        if ( in_array( get_post_type(), $post_types ) ) : ?>
            <footer class="entry-meta">
                <?php
                    generate_entry_meta();
    
                    if ( is_single() ) {
                        generate_content_nav( 'nav-below' );
                    }
                ?>
            </footer><!-- .entry-meta -->
        <?php endif;
    } );

    Let me know if this helps or not 🙂

    #661857
    Laurent

    Hi,

    Great ! It works !

    Are there other places in GeneratePress where I need to specificy things for custom post types ?

    Thanks a lot

    #662428
    Tom
    Lead Developer
    Lead Developer

    Nope, that should be it 🙂

    Glad I could help!

    #673101
    Alain Aubry

    I tried this:

    add_action( 'generate_after_entry_content', 'indigo_cpt_footer_meta' );
    function indigo_cpt_footer_meta() {
    	$post_types = array(
    		'colaborador',
    		'actividade',
    		'evento'
    	);
    	if ( in_array( get_post_type(), $post_types ) ) :
    		?>
    		<footer class="entry-meta">
    		<?php
    		generate_entry_meta();
    		if ( is_single() ) {
          			generate_content_nav( 'nav-below' );
    		} ?>
    		</footer><!-- .entry-meta -->
    		<?php
    	endif;
    }

    But the only thing I got is:

    <footer class="entry-meta">
    	<nav id="nav-below" class="post-navigation">
    		<span class="screen-reader-text">Navegação de artigos</span>
    	</nav><!-- #nav-below -->
    </footer>
    #673788
    Tom
    Lead Developer
    Lead Developer

    Can you link me to one of those post types?

    #673797
    Alain Aubry
    #673939
    Tom
    Lead Developer
    Lead Developer

    Hmm, how are you adding that code?

    #674036
    Alain Aubry

    Hi Tom

    A child theme based on yours, with lots of functions, many from yours, others well documented and tested, some my own experiments. I will send a login.

    Thanks

    #674508
    Tom
    Lead Developer
    Lead Developer

    In your custom function, find this line: generate_entry_meta();

    And add this after it:

    echo 'hi!';

    Does the “hi!” text appear within your CPTs?

    #674624
    Alain Aubry

    I tried locally, yes it shows in the right spot!

    But wait, those 3 CPT’s don’t have categories or tags.

    So the point is about generate_content_nav().
    This one is generating <span class="screen-reader-text">
    Also is generating </nav><!-- #nav-below -->

    #674864
    Tom
    Lead Developer
    Lead Developer

    So that means this function isn’t firing: https://github.com/tomusborne/generatepress/blob/35fe967ca7351a0517d258ab5c73150aa40d1f9a/inc/structure/post-meta.php#L159-L185

    Do these custom post types have categories and tags?

    #675000
    Alain Aubry

    Those 3 CPT’s don’t have categories or tags.
    ‘colaboradores’ has ‘grupos’, ‘actividades’ has ‘tipos’ but these does not count.

    I am really interested in the next/previous links. I cant discard the use of generate_entry_meta().
    So the point is about generate_content_nav().

    Thanks

    #675207
    Alain Aubry

    Hi Tom

    FOUND! As these CTP’s does not have categories or tags generate_content_nav() is failing to work.

    Somewhere else I have:

    add_filter( 'generate_category_post_navigation', 'indigo_category_post_navigation' );
    function indigo_category_post_navigation() {
    	// return true;
    	return false;
    }

    I have it set to true, which works fine with my posts, I switched to false and generate_content_nav() started to work.

    So I changed this filter to selectively pass true or false.

    add_filter( 'generate_category_post_navigation', 'indigo_category_post_navigation' );
    function indigo_category_post_navigation() {
    	$post_types = array(
    		'colaborador',
    		'actividade',
    		'evento'
    	);
    	if ( in_array( get_post_type(), $post_types ) ) :
    		return false;
    	else :
    		return true;
    	endif;
    }

    Also I changed to priority of ‘indigo_cpt_footer_meta’ to 20 to go below other stuff hooked there.

    I have to say that your code is very clear and easy to follow.

    Thank you so much!

    Alain

    #675593
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad you got it working 🙂

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.