WordPress.org

Ready to get started?Download WordPress

Forums

Writing My 1st Plugin, Add Posts to Category by Length (2 posts)

  1. blogachover
    Member
    Posted 4 years ago #

    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

  2. blogachover
    Member
    Posted 4 years ago #

    any advice anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic