Title: PHP function outside the loop and conditional statement for different post type
Last modified: August 21, 2016

---

# PHP function outside the loop and conditional statement for different post type

 *  Resolved [Pancho Perez](https://wordpress.org/support/users/lonchbox/)
 * (@lonchbox)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/php-function-outside-the-loop-and-conditional-statement-for-different-post-type/)
 * I´m using the PHP function to call YARPP posts outside of the post loop, also
   I use single.php for two different post_types. This is ok?
 *     ```
       <?php if (is_singular('rezepte')): ?>
       			<?php if(function_exists('related_posts')){
       					related_posts(array(
       				  'post_type' => array('rezepte'),
       				  'show_pass_post' => true,
       				  'past_only' => false,
       				  'threshold' => 0,
       				  'template' => 'yarpp-template-rezepte.php',
       				  'limit' => 3,
       				  'order' => 'score DESC'
       				), $post->ID , true);
       			} ?>
       		<?php else: ?>
       			<?php if(function_exists('related_posts')){
       					related_posts(array(
       				  'post_type' => array('post'),
       				  'show_pass_post' => true,
       				  'past_only' => false,
       				  'threshold' => 0,
       				  'template' => 'yarpp-template-posts.php',
       				  'limit' => 3,
       				  'order' => 'score DESC'
       				), $post->ID , true);
       			} ?>
       		<?php endif; ?>
       ```
   
 * The problem is everytime I get the same posts, no matter if I flush cache (yarpp
   experiments).
 * Any idea? Thanx.
 * [http://wordpress.org/plugins/yet-another-related-posts-plugin/](http://wordpress.org/plugins/yet-another-related-posts-plugin/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Pancho Perez](https://wordpress.org/support/users/lonchbox/)
 * (@lonchbox)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/php-function-outside-the-loop-and-conditional-statement-for-different-post-type/#post-4501954)
 * Fixed.
 * Just add this before the `related_posts` array
 *     ```
       wp_reset_query();
       related_posts(array(
       ```
   
 * And for the relation, increase the threshold to 1.
 *  Plugin Author [YARPP](https://wordpress.org/support/users/jeffparker/)
 * (@jeffparker)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/php-function-outside-the-loop-and-conditional-statement-for-different-post-type/#post-4502025)
 * Great! Glad that’s working for you now.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP function outside the loop and conditional statement for different
post type’ is closed to new replies.

 * ![](https://ps.w.org/yet-another-related-posts-plugin/assets/icon-256x256.png?
   rev=2549977)
 * [YARPP - Yet Another Related Posts Plugin](https://wordpress.org/plugins/yet-another-related-posts-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yet-another-related-posts-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/reviews/)

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 2 replies
 * 2 participants
 * Last reply from: [YARPP](https://wordpress.org/support/users/jeffparker/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/php-function-outside-the-loop-and-conditional-statement-for-different-post-type/#post-4502025)
 * Status: resolved