Forums

[resolved] Custom category checklist using quick post widget (2 posts)

  1. jnorion
    Member
    Posted 1 year ago #

    I'm dealing with a small but frustrating problem which I thought was going to be easy and has turned out not to be.

    I am using WordPress to create a sortable to-do list at work. I have created a category called "To Do" (with the slug as simply "todo"), with a child category for each employee ("JN", "AA", etc.). I have the Quick Post Widget plugin installed and activated on the front end. By default it creates a checklist of all categories on the site, and when you post something using it you can select one or more.

    What I am trying to do is restrict the category checklist to only the To Do category and its children. The checklist is created from within the plugin using the following code:

    <?php if ($cat_list_type == 'checklist') { ?>
    	<div id="quick_post_cat_checklist" style="<?php echo $cat_checklist_style; ?>">
    		<ul id="cats">
    			<?php wp_category_checklist(0, 0, $_POST['post_category'], false, null, false);?>
    		</ul>
    	</div>
    <?php } ?>

    Unfortunately I can find almost no documentation on the wp_category_checklist() function. I've changed a few arguments on the function call based only on looking at the code in template.php, but none of the changes have changed the way it operates at all, which is confusing to me.

    Can anyone explain how this works, or if there's a better workaround to accomplish this? My end goal is to have a quick post box with two or three different category selection areas, one for employee name, one for job name, etc.

    Thanks!

  2. jnorion
    Member
    Posted 1 year ago #

    Hmm, apparently I posted too quickly. I'm not sure what changed but for good measure I went back to play with it again, and this time it's worked perfectly.

    It appears the second argument of wp_category_checklist() is unknown_type $descendants_and_self, which takes a category ID number as input. For some reason it didn't do what I expected before, but now it is. When supplied with 7 (ID for the To Do category) it shows only that category and its descendants. Also, repeating the process with a different parent results in two sets of checkboxes which combine, allowing me to have one window for employee and a different one for jobs.

    Here's my new code:

    <?php if ($cat_list_type == 'checklist') { ?>
    	<div id="quick_post_cat_checklist" style="<?php echo $cat_checklist_style; ?>">
    		<ul id="cats">
    			<?php wp_category_checklist(0, 7, $_POST['post_category'], false, null, true);?>
    		</ul>
    	</div>
    <?php } ?>
    
    <?php if ($cat_list_type == 'checklist') { ?>
    	<div id="quick_post_cat_checklist" style="<?php echo $cat_checklist_style; ?>">
    		<ul id="cats">
    			<?php wp_category_checklist(0, 9, $_POST['post_category'], false, null, true);?>
    		</ul>
    	</div>
    <?php } ?>

    For reference, this begins on line 416 of quick-post-widget.php.

Topic Closed

This topic has been closed to new replies.

About this Topic