Support » Plugin: Related Posts by Taxonomy » "No related posts found" text not showing up

  • Resolved Doremdou

    (@doremdou)


    Hello again πŸ™‚

    I’ve got a little problem using the shortcode:

    [related_posts_by_tax include_terms=”628″ taxonomies=”post_tag” post_types=”post” format=”links” title=”” orderby=”post_date” order=”DESC”]

    when there is something to display, links are displaying correctly, but when there is nothing, it is displaying… nothing.

    I would like it to show the following message:
    “No related posts found”
    (for links, and thumbnails shortcodes too)

    How can I do that? πŸ™‚

    In my related-post-links.php there is this piece of code

    <?php else : ?>
    <p><?php _e( 'No related posts found', 'related-posts-by-taxonomy' ); ?></p>
    <?php endif ?>

    So I don’t understand why this message is not displaying…
    Could you help me?
    thank you very much πŸ™‚

    https://wordpress.org/plugins/related-posts-by-taxonomy/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    The template is never called if there are no related posts found.

    As of now this is only possible for the widget with the related_posts_by_taxonomy_widget_hide_empty filter.

    I will create the same for the shortcode and will put it in a beta version of the plugin after this weekend.

    If you’re using your own templates, and cannot wait that long, put this in your theme’s functions.php as a workaround:

    add_filter( 'related_posts_by_taxonomy',  'rpbt_show_empty_shortcode', 15, 4 );
    
    function rpbt_show_empty_shortcode( $results, $post_id, $taxonomies, $args ) {
    
    	// for shortcode only
    	if ( ! ( isset( $args['type'] ) && ( 'shortcode' === $args['type'] ) ) ) {
    		return $results;
    	}
    
    	// change empty array to "no_posts_found"
    	if ( empty( $results ) ) {
    		return 'no_posts_found';
    	}
    
    	return $results;
    }

    and change this in your “related-post-links.php” template:

    <?php if ( $related_posts ) : ?>

    to this

    <?php if ( $related_posts && is_array( $related_posts ) ) : ?>

    Thread Starter Doremdou

    (@doremdou)

    It is working like a charm thank you keesiemeijer ! πŸ™‚

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘"No related posts found" text not showing up’ is closed to new replies.