Home › Forums › Pro Support › Show Related Posts & Exclude Post
- This topic has 18 replies, 2 voices, and was last updated 2 years, 8 months ago by
Tom.
-
AuthorPosts
-
August 28, 2020 at 3:56 pm #18717
Connor
ParticipantHey Tom,
I have what I believe to be two very simple questions (I hope).
First, I have WP Show Posts set up to show 3 posts at the bottom of each blog post. My questions are as follows:
1. I want to only show posts that are in the same category as the blog post. So, for example, if a blog post is in the budgeting category, I want the three posts shown by WP Show Posts to be in the Budgeting category. I have tried some of the snippets floating around the forum to no avail. An example post is https://afterschoolfinance.com/save-money-tight-budget/
2. I am trying to exclude a post (post 3595) from WP Show Posts. However, it still seems to be showing up.Thank you so much in advance for your help!
Best,
Connor
August 29, 2020 at 2:03 pm #18750Tom
KeymasterHi there,
1. You can try doing this in the shortcode:
[wp_show_posts id="123" settings="taxonomy=category&tax_term=current"]
You just need to change the
123
to the ID of your list.2. Just to confirm, you’ve added the post ID into the Exclude posts field, but that post is still displaying in the list?
August 29, 2020 at 2:41 pm #18756Connor
ParticipantHi Tom,
1. This shortcode works perfectly, thank you!
2.Yes, Under WP Show Posts -> Selected List -> More Settings I have entered “3595” in the Exclude Post IDs field. For an example if where this shouldn’t be displaying, if you go to this post (https://afterschoolfinance.com/live-below-your-means/), the first post at the bottom where WP Show Posts displays is Christmas on a Budget. This is post 3595, which I have tried to exclude because it is seasonal.
Thanks!
August 30, 2020 at 10:10 am #18766Tom
KeymasterStrange, I wonder what the query is showing.
Try this debugging code:
add_filter( 'wp_show_posts_shortcode_args', function( $args ) { var_dump($args); return $args; } );
What is the output above that list?
August 30, 2020 at 10:55 am #18775Connor
ParticipantIt’s showing the following
array(8) { ["order"]=> string(4) "desc" ["orderby"]=> string(4) "date" ["post_type"]=> string(4) "post" ["posts_per_page"]=> int(3) ["ignore_sticky_posts"]=> bool(true) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "category" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(6) "saving" } ["operator"]=> string(2) "IN" } } ["post__not_in"]=> array(1) { [0]=> int(3401) } }
August 30, 2020 at 12:44 pm #18780Tom
Keymaster["post__not_in"]=> array(1) { [0]=> int(3401) }
This means that the ID you’re excluding is
3401
. Perhaps it’s a different list?August 30, 2020 at 12:58 pm #18782Connor
ParticipantHey Tom,
I have confirmed this is the list that is hooked in below the post content, so I don’t think that’s the issue. 3401 is the current post which it is excluding (per the checkbox in the “More” settings). However, it doesn’t seem to be excluding post-ID 3595 as well.
August 30, 2020 at 1:11 pm #18784Tom
KeymasterAh, so you have it set to exclude the current post as well? What if you un-check that option?
August 30, 2020 at 1:17 pm #18786Connor
ParticipantOddly, even when I uncheck that option, it is still excluding the current post and not the one I have specified.
August 31, 2020 at 8:14 pm #18808Tom
KeymasterCan you share the updated debug code that you shared above? Looking at the code, un-checking the “Exclude current” option should do the trick, but it would be helpful to see the var_dump info.
September 1, 2020 at 11:10 am #18827Connor
ParticipantHi Tom,
Here’s what is showing with “Exclude current” unchecked and post 3595 listed to be excluded:
array(8) { ["order"]=> string(4) "desc" ["orderby"]=> string(4) "date" ["post_type"]=> string(4) "post" ["posts_per_page"]=> int(3) ["ignore_sticky_posts"]=> bool(true) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "category" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(6) "saving" } ["operator"]=> string(2) "IN" } } ["post__not_in"]=> array(1) { [0]=> int(3401) } }
September 1, 2020 at 1:50 pm #18842Tom
KeymasterSo what is
3401
? Is that the current post that the list is on? Do you have any other custom functions added to the site?September 1, 2020 at 2:16 pm #18845Connor
ParticipantYes, 3401 is the current post. I do have a number of other custom functions added through Snippets, but none of them are related to WP Show Posts.
September 2, 2020 at 3:05 pm #18873Tom
KeymasterThis looks like a bug on our end – the current post is excluded no matter what if it’s on a single post, which is overwriting your own exclusions. Will get a fix committed ASAP and will update you 🙂
September 2, 2020 at 5:09 pm #18882Connor
ParticipantAwesome, thanks Tom! I’m glad I’m not going crazy! Should it be possible to exclude both the current post and my own selected exclusions once this is fixed?
-
AuthorPosts
- You must be logged in to reply to this topic.