Support » Plugins » Hacks » 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

    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

    # 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.



Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.


    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.