• I run financial blog https://www.fxg8.com and I wonder how to add function to auto assign category to post according time (on server) of publishing, so they can be sorted in sessions, for example if posts are published:

    • Monday-Friday 23:30-10:00 to be assigned to Tokyo category,
    • Monday-Friday 10:00-16:30 to be assigned to London category,
    • Monday-Friday 16:30-11:30 to be assigned to New York category,
    • Friday 23:30 – Sunday 23:30 to be assigned to Weekend category.

    Any help is very much appreciated. Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Did you mean:
    Sunday: 23:30-00:00 to be assigned to Tokyo category,
    Monday-Friday 00:00-10:00 to be assigned to Tokyo category,
    Monday-Friday 10:00-16:30 to be assigned to London category,
    Monday-Friday 16:30-23:30 to be assigned to New York category,
    Friday 23:30 – Sunday 23:30 to be assigned to Weekend category.

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this [untested]: https://pastebin.com/Vn6U7usD

    Thread Starter fxg8

    (@fxg8)

    Hey thanks a lot keesiemeijer!
    You have correctly separated the tasks in the lines above.
    Shall I just paste it in the functions.php and expect when post is published session category to be assigned automatically. I am going to test it, please advice if there is any other steps or avove would do.
    Maybe I could use your contact for any commission work if/when needed in the future? Marti

    Moderator keesiemeijer

    (@keesiemeijer)

    Put the code in your theme’s functions.php
    Just publish or edit a post and the category will be set (depending on the time) to the categories you edited in the code.
    Try and see what the time is set at your server by putting this somewhere in your theme’s index.php:

    <?php echo 'time now = '.date('G:i',strtotime("now")); ?>
    Thread Starter fxg8

    (@fxg8)

    Thanks, the function works when, as you say, publish or edit a post.

    1. The specific thing, here, however is, that posts are published automatically with auto rss plugin, and as they maybe between 10 and 60 every 2 hour, I’d rather not open and save every post manually. I currently assign the session (Tokyo, London, New York, Weekend) categories with Batch categories plugin, which is fast, but still manual.

    2. Another thing – I use paid (few bugs) auto assign categories plugin, which assigns posts according to words in post/title which match categories. When the new function (given at https://pastebin.com/Vn6U7usD by you) is inserted, the auto assign categories plugin conflicts with it.

    Can the function you suggested work, for example scan posts when activated (maybe by clicking on a link) ot at a given time by itself in order to save manual work. If you like I could also send you the auto assign categories plugin (small, 54 lines), where maybe the function can be added and categories assigned automatically together with the matching keywords.

    Sorry if it’s too complicated. I would understand if it’s too much to deal with. Thanks again. fxswiss(AT)yahoo.com

    Moderator keesiemeijer

    (@keesiemeijer)

    1)Is it that with my code only the time dependent category is set when saving a post?
    2)Do you want previous posts updated with the the time dependent categories from my code?

    the auto assign categories plugin conflicts with it.

    3) what is the conflict?

    Can you paste and submit the full code of the “auto assign categories plugin” into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

    Sorry if it’s too complicated

    maybe it is.

    Thread Starter fxg8

    (@fxg8)

    1. With your code post session category is assigned when adding new/edit/quick edit (currently removing existing categories) post, which at this website happens rarely and is not main goal.
    2. Yes, I want previous (already published) posts updated with the time dependent categories from my code, without removing any existing categories. THIS IS MY MAIN GOAL!
    I hope the workaround feature is not too much trouble and I am really grateful. Thanks.

    Moderator keesiemeijer

    (@keesiemeijer)

    I think your request is too specific for these forums. Maybe you need to hire a professional. https://jobs.wordpress.net/

    Thread Starter fxg8

    (@fxg8)

    Hey, thanks very much anyway, I will follow your advice or try working further on the code you gave me. Regards – Marti

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to auto assign category to post according time?’ is closed to new replies.