We're merging with GenerateBlocks! Learn more here.

[Support request] Related Posts

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Related Posts

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #27126
    Bizhan
    Participant

    Hello
    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

    #27128
    elvin
    Moderator

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

    #27280
    Bizhan
    Participant

    Hello
    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

    #27287
    elvin
    Moderator

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

    #28490
    Bizhan
    Participant

    Hi 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

    #28518
    elvin
    Moderator

    Also 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 inside wpsp_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.

    #28569
    Bizhan
    Participant

    Hi
    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

    #28650
    elvin
    Moderator

    Strange.

    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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.