We're merging with GenerateBlocks! Learn more here.

[Resolved] Related Post

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Related Post

Viewing 15 posts - 1 through 15 (of 41 total)
  • Author
    Posts
  • #20962
    Samuel
    Participant

    Hi,

    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?

    #21016
    David Beckwith
    Participant

    Hi 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.

    #21018
    Samuel
    Participant

    Hi 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 ?

    #21024
    David Beckwith
    Participant

    OK – 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 ?

    #21039
    Samuel
    Participant

    Yes,

    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?

    #21167
    Tom
    Keymaster

    WPSP 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 🙂

    #21201
    Samuel
    Participant

    Hi,

    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) } }

    #21224
    Tom
    Keymaster

    So 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?

    #21234
    Samuel
    Participant

    Well, 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.

    #21426
    Tom
    Keymaster

    Ah, 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.

    #21514
    Samuel
    Participant

    Hi 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
      1. 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-Category

    For 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.

    #21517
    Samuel
    Participant

    Sorry 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 Category

    Colombia
    – Andes
    — Bogota
    — Medellin
    – Caribean
    — Cartagena
    — Santa Marta

    #21541
    Tom
    Keymaster

    I 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.

    #21583
    Samuel
    Participant

    Hi,

    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
    – Bogota

    But WPSP is showing posts from :

    Andes
    – Medellin
    – Santander
    – Zona Cafetera

    #21653
    Tom
    Keymaster

    So 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' ) );
    }
Viewing 15 posts - 1 through 15 (of 41 total)
  • You must be logged in to reply to this topic.