Apna Garage
PHP, WordPress Codes
Home
WordPress
Saturday, 4 June 2016
Get Related Posts (Posts Under Same Category/Tags)
// get related posts $term_list = wp_get_post_terms(get_the_ID(), 'my_taxonomy', array("fields" => "ids")); $args = array( 'post_type' => 'my_post_type', 'post__not_in' => array(get_the_ID()), 'orderby' => 'rand', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'articles_cat', 'field' => 'term_id', 'terms' => $term_list, 'operator' => 'IN', ), ), ); $query = new WP_Query($args); while ( $query->have_posts() ) : $query->the_post(); echo $post->ID; echo $post->post_title; echo $post->post_content; echo '
'; echo get_permalink(); endwhile; wp_reset_query();
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment