Home › Forums › Pro Support › Related Post
- This topic has 40 replies, 3 voices, and was last updated 2 years, 10 months ago by
Tom.
-
AuthorPosts
-
October 11, 2020 at 8:41 am #20962
Samuel
ParticipantHi,
I’m trying to use WPSP to display related post but I have a problem.
I tried using this function
<?php if ( is_single() ) { $cats = get_the_category(); $cat = $cats[0]; } else { $cat = get_category( get_query_var( 'cat' ) ); } $cat_slug = $cat->slug; $list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' ); wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' ); ?>
I also tried with this shortcode [wp_show_posts id=”XXX” settings=”taxonomy=category&tax_term=current”]
(by the way Is there a preferable way to do it ?)
Both way, my problem is that it shows almost always same posts. I tried the “random” option but it’s displaying new post each time you refresh the page so I don’t thing it’s really good for SEO.
Do you have a special trick to have more variety in the results?
October 12, 2020 at 9:47 am #21016David Beckwith
ParticipantHi there,
the Random option should work fine. It may be that your server has page caching which would mean you’re seeing cached content on each refresh.
October 12, 2020 at 9:51 am #21018Samuel
ParticipantHi David,
Not sure to understand.
Actually random option is displaying different posts on each refresh. And this, I don’t want, because it’s not good for SEO.
But do you mean it’s caching system that is provoking that ?October 12, 2020 at 9:54 am #21024David Beckwith
ParticipantOK – i think we have our wires crossed.
So if you disable Random. What is the issue ? Are you seeing the same posts regardless of the Category of the current post ?October 12, 2020 at 11:08 am #21039Samuel
ParticipantYes,
I chose the “parent” option because it’s the only option that is displaying a variety of posts on each post, but I really have the impression that it’s choosing posts in “Category” but does not take into account “sub-categories” or “sub-sub-categories”.
Here is an example : https://monvoyageencolombie.com/visiter-monserrate-bogota/#informations-pratiques1
It’s a post regarding the city of Bogota. Category of this post is Colombia > Andes > Bogota
There is 10 posts in this category so it should be enough to find posts to display, posts that would be the most relevant here.But as you’ll see there is not one post directly related to this category. WPSP displays posts regarding “Medellin” which is in Colombia/Andes/Medellin category, “Cali” which is in Colombia/Andes/Cali category, etc. All are in the “Andes” sub-category but none in the “Bogota” sub-sub-category.
Is it possible to refine this?
October 14, 2020 at 1:54 pm #21167Tom
KeymasterWPSP itself wasn’t originally built to be a related posts plugin – you may be better off using a plugin built for the job.
However, your current setup looks like it would work for what it is.
We can debug the query to see what WordPress is requesting from the server.
1. Update to 1.2.0: https://wpshowposts.com/wp-show-posts-1-2-0/
2. Add this function:
add_filter( 'wpsp_query_args', function( $args, $settings ) { if ( 123 === (int) $settings['list_id'] ) { var_dump($args); } return $args; }, 10, 2 );
If you update the
123
with your list ID, it should output some data above the list.Let me know 🙂
October 15, 2020 at 5:12 am #21201Samuel
ParticipantHi,
Here is the output :
array(7) { ["order"]=> string(4) "DESC" ["orderby"]=> string(6) "parent" ["post_type"]=> string(4) "post" ["posts_per_page"]=> int(4) ["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(7) ""andes"" } ["operator"]=> string(2) "IN" } } ["post__not_in"]=> array(1) { [0]=> int(22765) } }
October 16, 2020 at 10:33 am #21224Tom
KeymasterSo that list is:
Set to order by “parent”.
Set to display posts in the “andes” category
Set to exclude post 22765.Does that sound right?
October 16, 2020 at 10:53 am #21234Samuel
ParticipantWell, really I don’t know, I just put the function you gave me, open a random post and copy/paste the debug info…
I mean I don’t remember which post I opened to get the debug info but let’s imagine it was a post about the city of Bogota as it’s in Category Colombia/Andes/Bogota I imagine it’s displaying posts in the Andes category. But I would prefer that it displays posts in the Bogota category, which is a sub-category of Andes.October 20, 2020 at 2:06 pm #21426Tom
KeymasterAh, that’s likely where the issue is coming from.
For something like this, I would suggest that you use an actual related posts plugin that’s built for this exact kind of thing. While WPSP can do it, it takes quite a bit of tinkering to get the query right.
October 23, 2020 at 3:00 am #21514Samuel
ParticipantHi Tom, I was using a related post plugin but it was messing out each time I had to debug my website, deactivate/reactivate it, etc. And as I’m using your plugin to show posts, I found it good to know have to add another unnecessary plugin to do the job.
But there is something I don’t understand, so I made a test, here are my thoughts :
CATEGORY STRUCTURE
My Destination category structure was like this :
Category
- Sub-Category
-
Sub-Sub-Category
For example :
Colombia
– Andes
– Bogota
– Medellin
– Caribean
– Cartagena
– Santa Marta
Etc.PLUGIN BEHAVIOUR
I saw that your plugin was able to choose posts in the second level (Sub-Category) because for example :
- In a post about Cartagena that is classified in the “Colombia/Caribean/Cartagena” category, your plugin was able to display posts from the seconde level “Colombia/Caribean” sub-category only.
- In comparison, in a post about Bogota that is classified in the “Colombia/Andes/Bogota” category, your plugin was able to display posts from the seconde level “Colombia/Andes” sub-category.
So basically it was a good point because it seems that your plugin was able to see the second level category (sub-category) and was not just displaying random posts from the first level “Colombia” category.
(Hope your following me…)
And I had a hope, that deleting the first level category “Colombia” it could solve my problem. I decided to delete the “Colombia” category which at the end wasn’t very useful anyway.
NEW CATEOGRY STRUCTURE
So now my new Destination category structure is like this :
Category
– Sub-CategoryFor example :
Andes
– Bogota
– Medellin
Caribean
– Cartagena
– Santa Marta
Etc.PLUGIN BEHAVIOUR
I thought it could change the behaviour of your plugin and permit it to display posts in the second level category.
But it’s not. It still display same posts… so now just posts in the first level category.
October 23, 2020 at 3:15 am #21517Samuel
ParticipantSorry I wasn’t able to edit my post to make lists more comprehensive…
I should have put for the first category structure something like this :
Category
– Sub Cateogry
— Sub Sub CategoryColombia
– Andes
— Bogota
— Medellin
– Caribean
— Cartagena
— Santa MartaOctober 23, 2020 at 1:50 pm #21541Tom
KeymasterI think it’s best to go back to the debug info: https://wpshowposts.com/support/topic/related-post/#post-21201
Can we do another test where you know the post you’re debugging? It will be useful to know which category WPSP is querying the related posts from relative to the post we’re viewing.
October 24, 2020 at 5:39 am #21583Samuel
ParticipantHi,
Here is the debug info :
array(7) { ["order"]=> string(3) "ASC" ["orderby"]=> string(6) "parent" ["post_type"]=> string(4) "post" ["posts_per_page"]=> int(4) ["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(7) ""andes"" } ["operator"]=> string(2) "IN" } } ["post__not_in"]=> array(1) { [0]=> int(497) } }
The post is this one and category is marked as :
Andes
– BogotaBut WPSP is showing posts from :
Andes
– Medellin
– Santander
– Zona CafeteraOctober 26, 2020 at 2:18 pm #21653Tom
KeymasterSo that seems to be because it’s showing posts from the “Andes” category.
Querying the child category only would be ideal, but I’m not aware of how off the top of my head – it would definitely take some tinkering.
You could try replacing this:
if ( is_single() ) { $cats = get_the_category(); $cat = $cats[0]; } else { $cat = get_category( get_query_var( 'cat' ) ); }
With this:
if ( is_single() ) { $cats = get_the_category(); } else { $cat = get_category( get_query_var( 'cat' ) ); }
-
AuthorPosts
- You must be logged in to reply to this topic.