Tags related custom posts
-
Hi,
I installed Custom Post Type UI plugin and I created Custom Post Type called “products” which has a bult-in taxonomy Tags.
Now what I need, I created several custom posts and some of them have a several same tags. I need to create “Related products” on my page and I want to achieve it using tags. I used google a lot, the best article which seemed to fit my needs is this
According to article, I put this code into my single-products.php file
`
<?php
if ( ‘products’ == get_post_type() ) {
$taxs = wp_get_post_terms( $post->ID );
if ( $taxs ) {
$tax_ids = array();
foreach( $taxs as $individual_tax ) $tax_ids[] = $individual_tax->term_id;$args = array(
‘tag__in’ => $tax_ids,
‘post__not_in’ => array( $post->ID ),
‘showposts’ => 5,
‘ignore_sticky_posts’ => 1
);$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo ‘
<ul>’;
while ( $my_query->have_posts() ) :
$my_query->the_post();echo ‘
<li><a href=”‘ . the_permalink() . ‘”>’ . the_title() . ‘ </a></li>
‘;endwhile;
echo ‘</ul>
‘;}
wp_reset_query();
}
}
?>
`The problem is it had no effect. It shows no related products (=custom posts). Is there any way how to fix it? Or is there any way how to display tag related custom posts?
The topic ‘Tags related custom posts’ is closed to new replies.