Related post

<div class="sidebar col-md-3 col-md-offset-1 main-sidebar">
            <div id="recent-posts-2" class="widget_categories sidebar-widget widget_recent_entries">
              <h3 class="widget-title">Related Posts</h3>
              <ul>
                <?php
$post_type = 'investment';
$tax = 'sponsorship';

$counter = 0;


	
	$args = array(
		'post_type' => $post_type,
		"$tax" => $tax_term->slug,
		'post_status' => 'publish',
		'orderby' => rand,
		'post__not_in' => array ($post->ID),
		'posts_per_page' => 10
	);

	$my_query = null;
	$my_query = new WP_Query($args);
	if( $my_query->have_posts() ) {
		
		while ($my_query->have_posts()) : $my_query->the_post(); ?>
                <li><a href="<?php the_permalink(); ?>">
                  <?php the_title(); ?>
                  </a></li>
                <?php
		$counter += 1;
		endwhile;
	
    }
    wp_reset_query();
	
 ?>
              </ul>
            </div>
          </div>
Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: