Support » Plugin: Related Posts by Taxonomy » Not posting on Pages

  • Resolved jailavie

    (@jailavie)


    Hello – I got related posts by category to successfully show on my posts via the widget. However I also want to add to PAGES. I can’t seem to get this to work – I added the shortcode on this page but nothing shows: http://traverpolis.com/europe/france/
    Do I have to do something different to add to a page vs a post?

    Thanks,
    Jamie

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • jailavie

    (@jailavie)

    Never mind I figured out I did not have a post id attributed to pull in. Thanks!

    jailavie

    (@jailavie)

    Ah now I’m still having trouble. I want the page to display related posts based on a specific category, but the page itself isn’t part of the category. Can I do this? The support doc mentions term id, but I don’t see anywhere to find that… Here is my page: http://traverpolis.com/france/

    Plugin Author keesiemeijer

    (@keesiemeijer)

    moderator

    Hi jailavie

    Sorry for the late reply. Pages (post type) with taxonomies should work for the shortcode. For the widget you can add support to it by implementing this:
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/recipes/#widget_page

    Let me know if this is not the issue

    jailavie

    (@jailavie)

    Thank you – that added the ability to add the widget to pages, but since my template only puts widgets on posts and not pages, I still have to use the short code. The short code I added to this page will not pull in related posts based on category. (I have my pages categorized into the same categories as my posts.)

    On my page http://traverpolis.com/france/ the shortcode works if I add in a post id to reference:
    [related_posts_by_tax title=”Read More About This Country” post_id=”2638″ image_size=”medium” format=”thumbnails” posts_per_page=”-1″]

    However when I remove the post id, it doesn’t work. The problem with using the post id is that I want that particular post (2638) to show as well. There are 4 stories total in the France category. So I would prefer it to pull in ALL related posts that are in the “France” category. Is that possible?

    Plugin Author keesiemeijer

    (@keesiemeijer)

    moderator

    If I understand it right you want to pull in related posts from another page and include that page in the results.

    Try it with this in your child theme’s functions.php

    
    add_filter( 'related_posts_by_taxonomy', 'rpbt_include_post', 10, 4 );
    function rpbt_include_post( $results, $post_id, $taxonomies, $args ) {
    	if ( ! $results ) {
    		return $results;
    	}
    
    	$post = get_post( $post_id );
    	if ( $post ) {
    		array_unshift($results, $post);
    	}
    
    	return $results;
    }

    This will add the post to the related posts found.

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    jailavie

    (@jailavie)

    Thank you I figured it out! I added post_types=”posts,pages”instead of the post id itself. Thanks!

    -Jamie

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