Never mind I figured out I did not have a post id attributed to pull in. Thanks!
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/
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
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?
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.
Thank you I figured it out! I added post_types=”posts,pages”instead of the post id itself. Thanks!
-Jamie
hi @jailavie
i have same problem with theme twenty fourteen…
can you plz post the whole shortcode you worked out for U?
so you put a shortcode in sidebar code because your theme doenst have widgetsupport for pages just for posts…?
Hey @rmblfish – Sure, here you go:
[related_posts_by_tax title="Read More About This Country" post_types="posts,pages" image_size="medium" format="thumbnails" posts_per_page="-1"]
I think you need post_types=”posts,pages” for it to work across both pages and posts. I wanted the ability for PAGES to pull in related POSTS so this worked for me. Hope it helps.
Here’s an example live: http://traverpolis.com/france/
Thanks!
Jamie
-
This reply was modified 8 years, 5 months ago by
jailavie.
Hi @jailavie
Thanks for answering here 🙂