• Hi, thank you for Astra Theme!

    I have a CPT on my website and need to show Related Posts (CPTs) below every single CPT.

    I tried the snippet provided by @bsfherman in this post in my functions.php. The section only appears below single posts, but not in CPTs. Besides, no controls are shown in the corresponding section of Customizer >> Single CPT.

    What can be wrong?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @damen02,

    Let me discuss this with my team and I will post here if there’s any update.

    Kind regards,
    Aradhy 😊

    Thread Starter Daniel

    (@damen02)

    Hi! An update on this.

    I had an error on my CPT singular/plural slug. My mistake!
    I corrected it and now I can see related posts on single CPT. Sorry to bother you with this.

    BTW, there will be great to have the same controls that single posts in Customizer.
    Is there a way to enable this? May be with a snippet?

    Thanks!

    Hi @damen02,

    Appreciate your patience!

    There’s not much to control this for the CPTs. However, you can add the below mentioned filter to the functions.php file of the child theme to show related posts limited to the CPT.

    add_filter( 'astra_related_posts_supported_post_types', function( $post_types ) {
        if ( is_array( $post_types ) ) {
            $post_types[] = 'news_post'; 
        } else {
            $post_types = array( 'post', 'news_post' );
        }
        return $post_types;
    } );

    Make sure to replace the ‘news_post’ with your CPT name. If you need assistance in adding the filter, check out this doc.

    Kind regards,
    Aradhy 😊

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

The topic ‘Related Posts on Custom Posts Type’ is closed to new replies.