Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying related posts by tags on category template page in wordpress
    primarykey
    data
    text
    <p>I would like to display related posts by tags next to posts on category page. All related posts pieces of code I could find are to be used in nested loops on <code>single.php</code> but I need it to be in the loop on category page.</p> <p>So when you go to category "Cats" it should output the following: "Post 1 title", category "Cats", tag "Kittens" "Related post 1.1 title", tag "Kittens" "Related post 1.2 title", tag "Kittens"</p> <hr> <p>"Post 2 title", category "Cats", tag "tomcats" "Related post 2.1 title", tag "tomcats" "Related post 2.2 title", tag "tomcats"</p> <hr> <p>...</p> <p>This is the code I came up with, but it breaks.</p> <p>`// First query $my_query = new WP_Query('cat=6');</p> <pre><code>// If first query have posts if( $my_query-&gt;have_posts() ) : // While first query have posts while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;!-- start post --&gt; &lt;!-- End post div --&gt; &lt;?php // tags $tag_ids = array(); foreach($tags as $individual_tag) $tag_ids[] = $individual_tag-&gt;term_id; $args=array( 'tag__in' =&gt; $tag_ids, 'post__not_in' =&gt; array($post-&gt;ID), 'posts_per_page'=&gt;99, 'caller_get_posts'=&gt;1 ); // Second query $my_second_query = new WP_Query('$args'); // If second query have posts if( $my_second_query-&gt;have_posts() ) : ?&gt; &lt;?php // While second query have posts while( $my_second_query-&gt;have_posts() ) : $my_second_query-&gt;the_post(); ?&gt; &lt;!-- start post --&gt; &lt;!-- End post div --&gt; &lt;?php // End second while have posts endwhile; ?&gt; &lt;?php // End first while have posts endwhile; // End if first query have posts endif; ?&gt;` </code></pre> <p>Is this even possible? I couldn't for the life of me find example. Many thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload