WordPress.org

Ready to get started?Download WordPress

Forums

Retrive post by tags PHP code (4 posts)

  1. TataVostru
    Member
    Posted 2 years ago #

    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 persoane

    register_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

  2. TataVostru
    Member
    Posted 2 years ago #

    nobody?

  3. TataVostru
    Member
    Posted 2 years ago #

    no suport for this?

  4. TataVostru
    Member
    Posted 2 years ago #

    For example, i am building a cinema site..

    The site is http://www.cinema.trancelevel.com

    For movies - I am using post - The movies are post there.. For actors - I am using post_type : persoane , Taxonomy : lista.

    How can i retrive the movies play by bruce willis in
    http://cinema.trancelevel.com/persoane/bruce-willis/

    For example, i have : http://cinema.trancelevel.com/the-cold-light-of-day-2012-2/ This movie have Bruce Willis Tag....( this is a regolar post in wp)

    In Bruce Willis page i want to retrive the movie.... that have Bruce Willis Tag

    In conclusion i want to display the movies that actor play in

    I anny body know please help. Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags