Custom Post type category pages template and loop

You may alter the main query before the loop, but it’s crucial to reset the main query afterwards. Otherwise you’ll probably run into problems elsewhere. Disclaimer: Doing this is officially discouraged by WordPress here. However, in my experience it works perfectly to achieve the behaviour you want. Just don’t forget to add wp_reset_query(); after closing … Read more

How to display Related Posts based on number of taxonomy terms matched

Let’s split the problem up in three bits: retrieving the related posts from the database, sorting them and displaying the result. Post retrieval This is possible using the taxonomy parameters offered in WP_Query. Let’s first retrieve the category of the current post and find their IDs: $categories = get_the_terms( get_the_ID(), ‘news-category’ ); foreach ( $categories … Read more