[Resolved] Issue generate_entry_meta_post_types and CPT

Home Forums Support [Resolved] Issue generate_entry_meta_post_types and CPT

Home Forums Support Issue generate_entry_meta_post_types and CPT

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1488501
    Beate

    Hello,

    I habe created Custom Post Type and output the entry meta with this function:

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

    Issue: The click on the author link leads to “404”, although the author had written several articles for this cpt.

    Can you help me please?
    Regards

    #1488784
    David
    Staff
    Customer Support

    Hi there,

    WP doesn’t display CPTs on author pages by default.
    Try the snippet Tom provides here to correct that:

    https://generatepress.com/forums/topic/displaying-pages-and-posts-on-author-page/#post-956072

    #1489938
    Beate

    Hi David,

    thanks for the answer. I have inserted:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! $query->is_main_query() || is_admin() ) {
            return;
        }
    
        if ( $query->is_author ) {
            $query->set( 'entwickler-blog', array( 'post', 'page' ) );
        }
    } );

    The error is unfortunately still there. The link to the author still leads to 404.

    #1490002
    David
    Staff
    Customer Support

    This line is incorrect:

    $query->set( 'entwickler-blog', array( 'post', 'page' ) );

    it should be:

    $query->set( 'post_type', array('custom_type', 'post') );

    Change the custom_type to the your CPT slug.

    #1490043
    Beate

    My mistake is very embarrassing…

    Dear David, now it works and I am very grateful for your help!!!

    #1490066
    David
    Staff
    Customer Support

    No problems – glad to be of help!

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