Title: alx_related_posts function
Last modified: August 22, 2016

---

# alx_related_posts function

 *  Resolved [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/)
 * Hi – Thank you for this wonderful theme.
    How would I modify alx_related_posts
   function to exclude certain Categories from the related posts? I use the related
   by Tag option to show posts related by Tag underneath a post. I would like to
   exclude blog posts that match in 2 Categories from being shown. How would I tweak
   the code to do that? Thank you.

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

 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561673)
 * Hi Sharon. Took a quick look around and found [this article](http://www.locoed.com/web-design/how-to-exclude-category-posts-wordpress-tutorial-code/).
   Haven’t tried actually applying it to the function but might give you some ideas.
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561690)
 * Hello – Thank you for that – I will take a look!
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561840)
 * Hi Sharon. Just checking to see if you were able to resolve your question.
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561856)
 * Hello – I haven’t had a chance to look into it yet but will in the next few days–
   thanks for asking
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561906)
 * Hi Sharon. I think I have something that might work for you. This involves editing
   the functions.php file. After you set the initial categories to exclude, you’ll
   need to remember to update the function if you need to adjust the categories.
 * 1. In Post – Categories, edit each category you want to exclude and get the “
   tag_ID=” number from the URL.
    2. Copy the entire Related Posts function from
   the parent functions.php to your child theme functions.php. 3. Find the following
   code at the end of the “//Related by tags” section of the function:
 *     ```
       }
         if ( !$tags ) { $break = true; }
         }
       ```
   
 * 4. Between the code line and the closing bracket, add three new lines of code
   so it looks like this:
 *     ```
       }
         if ( !$tags ) { $break = true; }
         else {
           // Define categories to exclude
           $args['category__not_in'] = array( 1,2,3 );
         }
       ```
   
 * 5. Replace the ( 1,2,3 ) with the category IDs you selected in #1 above.
    6. 
   Test.
 * Let me know how that works.
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561909)
 * Hello – Thanks so much for doing that – I will try that today and let you know
   how it goes!
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561915)
 * Hello – That seems to be working nicely, thank you! Are you a Hueman theme author
   by the way?
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561916)
 * Glad is’t working for you. Nope, not a Hueman theme author. Just someone who 
   uses the theme and likes to help other users as a way to give back to the WP 
   community and Alex in particular for contributing the theme.
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561918)
 * You are a gentleman and a scholar and I thank you :-).
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561919)
 * Thanks for the kind words. If you’re satisfied with the results please mark this
   topic as resolved.
 *  Thread Starter [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * (@prettybiddy)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561920)
 * Will do.

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

The topic ‘alx_related_posts function’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/hueman/3.7.27/screenshot.png)
 * Hueman
 * [Support Threads](https://wordpress.org/support/theme/hueman/)
 * [Active Topics](https://wordpress.org/support/theme/hueman/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/hueman/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/hueman/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [Sharon](https://wordpress.org/support/users/prettybiddy/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/alx_related_posts-function/#post-5561920)
 * Status: resolved