Support » Plugins » Writing My 1st Plugin, Add Posts to Category by Length

  • I am attempting to write a simple plug-in which should be called before publishing a post. What it is supposed to do is to automatically add the post to a category called “short” if it is less than 1000 characters in length. (We have our reasons :-).)

    Give that I don’t even know how to do debug output without breaking all sorts of things, I beg your indulgence and support because I could be doing just about everything wrong.

    Can one use “the_content” before a post is published? Am I adding the category correctly? Because it’s a pretty simple plug-in, an experienced developer will probably spot the problem in a minute.

    add_action (“publish_post”, “make_short”) ;

    function make_short($post_ID) {
    if ( (!in_category(“short”, $post_ID)) && (strlen(the_content()) < 1000)
    ) {
    $postcats = wp_get_post_categories($post_ID);
    $postcats = $postcats + array(“short”);
    wp_set_post_categories ( $post_ID, $postcats);
    }
    }

    Thank you!

    Yaakov

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Writing My 1st Plugin, Add Posts to Category by Length’ is closed to new replies.