• Resolved stug2013

    (@stug2013)


    Hi, I realize that I can change on a global way whether related posts are shown at the bottom of posts by going into theme options, but I have a custom post type that I would like them not to appear on. I wondered if it might be able to be done in such a way that you could say if a post belonged to a certain category then don’t show related posts?
    Anyone else faced this same type of problem?
    I actually have some custom post types that related posts do not show up on but another that they do. I can’t see anything that I am doing differently but would like some way to control it.
    If anyone else is using learndash it is to do with that, lessons and courses are fine but related posts show up with topics.
    thanks so much for any help

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter stug2013

    (@stug2013)

    I have had another look and I can only associate tags with this type of custom post (learndash topics). So instead of categories I think I would need to be able to not display related content based on a post having a certain tag.

    Hi stug2013. This thread discusses using the Tag option to filter posts, and excluding posts by category. Not sure how you’re filtering the Related Posts but this might give you an idea of how to accomplish your objective.

    Thread Starter stug2013

    (@stug2013)

    Hi bdbrown thank for the pointer but I think this is a different type of fix to the one I need. I think my explanation above is probably a bit sketchy.
    The situation is this. For all my posts so far I like to have the related post shown at the bottom, which I have set in theme options. However now I have a particular custom post type that I don’t want any related posts shown at all. I am trying to figure a way to achieve this. I thought I might be able to identify this custom post type by assigning a specific category to it but for some reason you can only add tags. Not sure if this is the direction to go anyway.
    glad of any other ideas

    OK, think I’ve got it. Since you don’t want to display the Related Posts at all for that post type, maybe a better approach would be to back up a level and catch the call at the point of origin in single.php. If you copy single.php to your child theme you’ll find these three lines at the bottom of the file:

    <?php if ( ot_get_option( 'post-nav' ) == 'content') { get_template_part('inc/post-nav'); } ?>
    
    <?php if ( ot_get_option( 'related-posts' ) != '1' ) { get_template_part('inc/related-posts'); } ?>
    
    <?php comments_template('/comments.php',true); ?>

    Wrap the second line with a test for the post type:

    <?php if ( ot_get_option( 'post-nav' ) == 'content') { get_template_part('inc/post-nav'); } ?>
    
    <?php if ( get_post_type() != 'custom_post_type' ): ?>
         <?php if ( ot_get_option( 'related-posts' ) != '1' ) { get_template_part('inc/related-posts'); } ?>
    <?php endif; ?>
    
    <?php comments_template('/comments.php',true); ?>

    Change ‘custom_post_type’ to your post type. Try that and see how it works.

    Thread Starter stug2013

    (@stug2013)

    Thanks a million bdbrown, works perfect!!

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

The topic ‘removing related posts for custom post types’ is closed to new replies.