Retrive post by tags PHP code
-
Hy i am tring to use this code to retrive the related content hy post.
Ex:
The Post – are the movies…
Other Post_Type – is persoaneregister_taxonomy("lista","persoane", array("hierarchical" => true, "label" => "Categorie", 'show_ui' => true, 'query_var' => true, "singular_label" => "lista", "rewrite" => true , 'with_front' => true));
The Code
<?php //for in the loop, display all "content", regardless of post_type, //that have the same custom taxonomy (e.g. genre) terms as the current post $found_none = '<h2>No related posts found!</h2>'; $taxonomy = 'lista';// e.g. post_tag, category, custom taxonomy $param_type = ''; // e.g. tag__in, category__in, but genre__in will NOT work $tax_args=array('orderby' => 'date'); $tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args); if ($tags) { foreach ($tags as $tag) { $args=array( $param_type => $tag->slug, 'post__not_in' => array($post->ID), 'post_type' => 'post', 'showposts'=> 1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php $found_none = ''; endwhile; } } } wp_reset_query(); // to use the original query again ?>
I put in post,normal post of wordpress the tag Bruce Willis
It shoud display the movie that actor Will Smith play in… wath i am doing rong.Thanks
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Retrive post by tags PHP code’ is closed to new replies.