Title: Plugin attempt: singleChildRedirect
Last modified: August 19, 2016

---

# Plugin attempt: singleChildRedirect

 *  [hquadrat](https://wordpress.org/support/users/hquadrat/)
 * (@hquadrat)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/plugin-attempt-singlechildredirect/)
 * Hi all,
 * I’m trying to achieve a simple behaviour: when a category has only one post assigned,
   then when the category is clicked, please WordPress, directly show this post (
   indestead of bugging me with an category overview with only one post listed).
 * # Pseudo code
 *     ```
       //check how many post are in a category
       query = "Select COUNT from CATEGORIES have articles"
   
       if (count == 1) {
           //check the post ID
           query2 = "Select the above postID"
           //and redirect
           wordpressRedirect(postID)
       }
       ```
   
 * It might become 15 lines in total but not far more I think.
 * # Where
 * The most difficult question for me is: where to place my code and which hook 
   to use (as far as I understood, hooks are specific points during runtime when
   WordPress renders a page and I can add my behaviour at those hooks)?
    [hooks documentation](http://codex.wordpress.org/Plugin_API/Action_Reference)
 * # Why
 * This behaviour would be very helpful setting up WordPress as a CMS: you could
   build the whole navigation up on categories (and not on pages as seen often) 
   and whenever the category is clicked you don’t see an article listing with one
   article but directly get redirected there.
 * Any help would be apreciated.
 * Rgds,
 * Henning

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

 *  Thread Starter [hquadrat](https://wordpress.org/support/users/hquadrat/)
 * (@hquadrat)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/plugin-attempt-singlechildredirect/#post-1622404)
 * I dug a little deeper in the docs: plugins_loaded hook seems a good entry point.
 * Can anyone give a comment on that? Especially regarding the fact that for the
   successful execution of my plugin WordPress needs to know a) if a category at
   all and b) which category should be displayed.
 * Thx.
 *  Thread Starter [hquadrat](https://wordpress.org/support/users/hquadrat/)
 * (@hquadrat)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/plugin-attempt-singlechildredirect/#post-1622405)
 * Ah, that sounds a little too early, maybe init or wp_loaded fit better? I’ll 
   try with init.
 * Even I’ll do some tests, any expert help is appreciated.

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

The topic ‘Plugin attempt: singleChildRedirect’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)
 * [single](https://wordpress.org/support/topic-tag/single/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 1 participant
 * Last reply from: [hquadrat](https://wordpress.org/support/users/hquadrat/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/plugin-attempt-singlechildredirect/#post-1622405)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
