Archived topic
wp show posts hide when no results
5 replies · Started by johnaps on January 19, 2022
Hello!
I am using wp show posts and this code i found on google to display related posts by tags in my right sidebar.
<div class="wpsp-related-posts1 grid-container">
<h2>Related Posts</h2>
<?php
if ( is_single() ) {
$tags = get_the_tags();
$tags_list = [];
foreach ($tags as $tag)
$tags_list[] = $tag->slug;
$tag_string = implode( ', ', $tags_list);
} else {
$tag_string = get_tag( get_query_var( 'tag' ) );
}
$list = get_page_by_title( 'relatedtags', 'OBJECT', 'wp_show_posts' );
wpsp_display( $list->ID, 'tax_term="' . $tag_string . '"' );
?>
</div>
I want to completely hide related posts by tags when there is no related results, instead of showing "Sorry, no posts were found."
Can you help me?
Hi there,
i am not sure its possible to do that without using some Javascript - can you change the WPSP list so it returns No Results ?
i am sorry i did a rollback and you couldnt see the plugin in action probably... please check the link again and you will see the “Sorry, no posts were found.” in my right sidebar!
Try this CSS:
.sidebar .wpsp-no-results {
display: none;
}
thank you! i didnt look for css classes you are very right! :)
No problem :)