Home › Forums › Pro Support › Related Posts
- This topic has 7 replies, 2 voices, and was last updated 2 years, 6 months ago by
elvin.
-
AuthorPosts
-
February 22, 2021 at 2:46 am #27126
Bizhan
ParticipantHello
I am trying to show tags of the same category under each post. In other words, all the posts shown under a blog post should have the same tag but also belong to the same category as the shown post.
I am using generatepress theme.Regards
February 22, 2021 at 3:30 am #27128elvin
ModeratorHi there,
I’m not sure what the goal is. I believe you’re asked something similar here? https://wpshowposts.com/support/topic/show-posts-from-a-category-and-a-tag-2/#post-26687
Can you explain a bit more how it should differ? Also, are you asking for the theme’s blog post lists or still on WPSP plugin? Let us know.
February 23, 2021 at 10:52 pm #27280Bizhan
ParticipantHello
I made a post list in wp-show-posts, called Raleted posts. Using the shortcode of this post list and using Elements-hock in generate_before_commen, I want to add related posts so the last 6 posts in the same category as the displayed post are displayed. Currently, using gp_related_posts plugin and bu setting filter by tags or category, I can display related tags but I want to display the shortcode in the desired place.Regards
February 24, 2021 at 12:15 am #27287elvin
ModeratorYou can try this PHP snippet on your GP Hook. Make sure Execute PHP is enabled.
<?php function wpsp_terms(){ $post_info = get_queried_object(); $categories = get_the_category($post_info->ID); $tax_term = array(); if( !empty($categories) ){ foreach( $categories as $category ) { $tax_term[] = $category->slug; } } return $tax_term; } var_dump(wpsp_terms()); $settings = array( 'taxonomy' => 'category', 'tax_term' => wpsp_terms(), ); wpsp_display( 1699, $settings ); ?>
Note: If there’s only 1 post on the category. Nothing will display because there’s no sibling posts within that category.
March 25, 2021 at 12:25 am #28490Bizhan
ParticipantHi Elvin
The PHP snippet you provided me not worked, Not show correct related posts.
Still GP Related Posts plugin working fine.
Also in above related articles show this code in front-end : array(1) { [0]=> string(20) “science-and-research” }
“science-and-research” is term one of post categories.
I have 9 categories and 23 Post tags.Regards
March 25, 2021 at 4:42 pm #28518elvin
ModeratorAlso in above related articles show this code in front-end : array(1) { [0]=> string(20) “science-and-research” }
Ah yes, that’s from the var_dump() i forgot to remove. Let’s remove that.
Try this code.
<?php function wpsp_terms(){ $post_info = get_queried_object(); $categories = get_the_category($post_info->ID); $tax_term = array(); if( !empty($categories) ){ foreach( $categories as $category ) { $tax_term[] = $category->slug; } } return $tax_term; } $settings = array( 'taxonomy' => 'category', 'tax_term' => wpsp_terms(), ); wpsp_display( 1699, $settings ); ?>
IMPORTANT: Make sure you change the
1699
insidewpsp_display( 1699, $settings );
to the related post list WPS ID you’re using. Else, it won’t know what to use and it won’t work.Strange, this code works on my end. Can explain a bit more on what’s going on? Perhaps you can link us to the page in question? Have you corrected the WPSP ID in the code?
Let us know.
March 26, 2021 at 7:24 am #28569Bizhan
ParticipantHi
Yes, I am using the correct WPSP ID in the code, Because of the productive website I can not enable WPSP.
https://www.scientific-editing.info/blog/ currently “GP Related Posts” plugin is enabled ( by Filter by Tags or Categories? Tags ) and you can check it.Regards
March 29, 2021 at 1:17 am #28650elvin
ModeratorStrange.
I’ve tested the code and it was working on my end.
Perhaps there’s an issue with how the code was added.
If you could temporarily provide us backend access, we could check out what seems to be the issue.
You can send the details through the contact page. https://wpshowposts.com/contact/
Alternatively, I was going to recommend
GP Related Posts
as WPSP isn’t exactly created to show related posts. -
AuthorPosts
- You must be logged in to reply to this topic.