Home » Topics » Pods 1.x » how do i produce a list of wp posts based on taxonomy tag in my pod page?
how do i produce a list of wp posts based on taxonomy tag in my pod page?
This topic contains 3 replies, has 2 voices, and was last updated by johnnyn 1 year, 4 months ago.
-
AuthorPosts
-
January 10, 2012 at 1:37 pm #167153
here is the scenario.
I have a pod page of medical treatments. This is the detail page, and on the bottom of this page I want a list of the related news posts that are tagged with the same treatment name. The news posts are regular wp posts, with tags "news" and "[treatment name]"e.g. if my pod detail page is "heart surgery" then, at the bototm of the page I want a list of all the news articles that are tagged with "heart surgery" (and of course "news")
the pod’s treatment name will be the same as the taxonomy tags used in my news articles.what would be the best way to do achieve this?
January 10, 2012 at 2:48 pm #167154I actually have this on my list to add to one of my sites. Thanks for spurring me to do the research on it now.
It looks like you can do something like this. See query_posts() on the WP-Codex for more information. You can also take a look at get_posts(), but the documentation there is severely lacking.
12345678query_posts('tag=news+heart-surgery');// set $more to 0 in order to only get the first part of the postglobal $more;$more = 0;// the Loopwhile (have_posts()) : the_post();the_content( 'Read the full post »' );endwhile;You should be able to create a pick field on the related taxonomy terms from within pods. I haven’t tried this yet. Note that the tag you pass to query_posts() should be the tag’s slug.
If you get this working, please post your code. I’m probably a month away from implementing this myself.
January 10, 2012 at 4:42 pm #167155thanks Chris, I will post what i end up doing.
January 11, 2012 at 3:21 pm #167156here is what i ended up using, thanks for the pointer Chris.
1234567891011<ul><?phpglobal $post;$tmp_post = $post;$args = array( 'numberposts' => 3, 'category_name' => 'news+heart-surgery' );$myposts = get_posts( $args );foreach( $myposts as $post ) : setup_postdata($post); ?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?><?php $post = $tmp_post; ?></ul>I believe the ‘category name’ argument uses a comma as "or" and a plus as "and" but I don’t think you can mix "AND" "OR", for example, the following did not work for me.
but these did work
12'category_name' => 'news+heart-surgery+heart-disease''category_name' => 'news,heart-surgery,heart-disease'I have used categories, but tags works just as well if you want to filter by tags instead of categories. Just change the argument as below.
I don’t see any way in the API to get both some articles from a category as well as some articles from tags, so you would probably have to run get_posts() twice and then join the results up.
update…
this is what i put on my pods detail page…
I have a field in my pod called "tag" this is what i am filtering by as well as the category "news"1234567891011121314151617<?phpglobal $post;$tmp_post = $post;$myNewsFilter = 'news+'.$pods->get_field('tag');$args = array( 'numberposts' => 3, 'category_name' => $myNewsFilter );$myposts = get_posts( $args );if($myposts){ // check that there are any related news articles?><h2>Related news articles</h2><ul><?phpforeach( $myposts as $post ) : setup_postdata($post); ?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?></ul><?php }// end if statement checking that related news exists ?><?php $post = $tmp_post; ?>you could probably use templates to do a better job
— edit
you can use categor_name as well as tag in the arguments. just add them both and it works. -
AuthorPosts
You must be logged in to reply to this topic.