WordPress.org

Ready to get started?Download WordPress

Forums

Create Category in a plugin (Help!!) (1 post)

  1. interrupt
    Member
    Posted 7 years ago #

    Hello, plugin-makers and wordpress-extenders

    I have created a plugin for filtering posts based on two sets of keywords. I had it working on one wordpress install(2.03) and am trying to test it on another (2.04).

    I have looked at what was changed in the changelog, but nothing applied, as far as I could tell. The plugin relies on Feedwordpress 0.98. This doesn't seem to affect the problem I am having. THe plugin hooks into syndicated_post which feedwordpress provides.

    I am trying to check if two required categories exist and if they don't then to create them as well. here is the code that doesn't work.
    /**************************************************
    /* Begin Post Filter Setup */

    function pf_set_up() {

    // Check if the 'tier_1_fail' category exists / create one

    $fail_cat_name = "tier_1_fail";
    // print $fail_cat_name + '/n';
    if(!get_cat_id($fail_cat_name)){
    wp_insert_category($fail_cat_name);
    }
    // print get_cat_id($fail_cat_name);

    // Check if the 'tier_1_pass' category exists / create one

    $pass_cat_name = "tier_1_pass";
    // print $pass_cat_name + '/n';
    if(!get_cat_id($pass_cat_name)){
    wp_insert_category($pass_cat_name);
    }
    // print get_cat_id($pass_cat_name);
    }

    /* End Post Filter Setup */

    NOTE: This next bit is a piece of the plugin code, specifically the first term search. THe category check was built into it at first and worked on 2.03. On 2.04 it doesn't work.
    /*************************************************
    /* Begin First Tier Keyword Search Function */

    function tier_1_search($post_array) { // First-tier keyword filter for posts being published
    // print('starting tier 1.. /n');

    // Check if the 'tier_1_fail' category exists / create one

    $fail_cat_name = "tier_1_fail";
    // print $fail_cat_name + '/n';
    if(!(get_cat_id($fail_cat_name))){
    wp_create_category($fail_cat_name);
    }
    $fail_cat_id = get_cat_id($fail_cat_name);

    // print $fail_cat_id + '/n';
    // Check if the 'tier_1_pass' category exists / create one

    $pass_cat_name = "tier_1_pass";
    // print $pass_cat_name + '/n';
    if(!get_cat_id($pass_cat_name)){
    wp_create_category($pass_cat_name);
    }
    $pass_cat_id = get_cat_id($pass_cat_name);

    // print $pass_cat_id + '\n';
    *************** end code snip ***** */

    I am sorry if this is considered too much code. Perhaps you will see that I am confusing which function to use for actually making a new category within the running plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags