Classifieds: Make Categories Requierd

Hi, How can I make categories required, so anyone must select a category or a sub-category before sent his ad?

  • mort3n

    Hi matrixd,

    OK, let's try something different :slight_smile:

    The plugin is really just a small script that looks for the id in some of the markup tags.

    I wonder if the script could be slightly modified to run on your site.

    Could you provide a link to a page where you would like the selection of a Category to be enforced? If it's a private site, then perhaps just go View source and find the markup for the Select and post that.


  • matrixd

    Thanks mort3n you must register to my site to the form so I send you the code from source code of that page. Some text are in greek language.

    <div id="taxonomy-classifieds_categories" class="cf_taxonomydiv">
    			<label>All Classified Categories</label>
    			<div id="classifieds_categories_all" class="cf_tax_panel">
    				<input type='hidden' name='tax_input[classifieds_categories][]' value='0' />				<ul id="classifieds_categories_checklist" class="list:Classified Categories categorychecklist form-no-clear">
    <li id='classifieds_categories-254' class="popular-category"><label class="selectit"><input value="254" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-254" /> ?????? ??????????</label><ul class='children'>
    <li id='classifieds_categories-257' class="popular-category"><label class="selectit"><input value="257" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-257" /> ??????????-????????????-???????</label></li>
    <li id='classifieds_categories-255'><label class="selectit"><input value="255" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-255" /> ?????????? ????????</label></li>
    <li id='classifieds_categories-256'><label class="selectit"><input value="256" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-256" /> ?????????</label></li>
    <li id='classifieds_categories-207'><label class="selectit"><input value="207" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-207" /> ????</label><ul class='children'>
    <li id='classifieds_categories-246' class="popular-category"><label class="selectit"><input value="246" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-246" /> ????????????</label></li>
    <li id='classifieds_categories-249' class="popular-category"><label class="selectit"><input value="249" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-249" /> ?????????? ?????</label></li>
    <li id='classifieds_categories-247' class="popular-category"><label class="selectit"><input value="247" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-247" /> ??????????</label></li>
    <li id='classifieds_categories-248'><label class="selectit"><input value="248" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-248" /> ???? ????? ?????</label></li>
    <li id='classifieds_categories-245'><label class="selectit"><input value="245" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-245" /> ???????????</label></li>
    <li id='classifieds_categories-250' class="popular-category"><label class="selectit"><input value="250" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-250" /> ??????</label><ul class='children'>
    <li id='classifieds_categories-253'><label class="selectit"><input value="253" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-253" /> ????? ??????</label></li>
    <li id='classifieds_categories-252'><label class="selectit"><input value="252" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-252" /> ?????????</label></li>
    <li id='classifieds_categories-251' class="popular-category"><label class="selectit"><input value="251" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-251" /> ?????? ??????</label></li>
    <li id='classifieds_categories-260'><label class="selectit"><input value="260" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-260" /> ???? ?????????</label></li>
    <li id='classifieds_categories-258'><label class="selectit"><input value="258" type="checkbox" name="tax_input[classifieds_categories][]" id="in-classifieds_categories-258" /> ??????</label></li>
    			<span class="description">Add or remove Classified categories</span>
  • mort3n

    Hi matrixd,

    Thanks for your input :slight_smile:

    If you open the plugin file, there are some places that you could try to modify:


    Here #publish refers to the Publish button. That is, the function checking for a selected category should run when the publish or in your case Save button is clicked. You need to find the button parameter to use within the page source.

    The next block

    var cats = jQuery('[id^=\"taxonomy\"]')

    finds tags called taxonomy with tags called selecit embedded and input tags further embedded. This appears to correspond to the code you posted above, so should work.

    The following code is specific to the admin pages, so delete those

    setTimeout(\"jQuery('#ajax-loading').css('visibility', 'hidden');\", 100);
          jQuery('[id^=\"taxonomy\"]').find('.tabs-panel').css('background', '#F96');
          setTimeout(\"jQuery('#publish').removeClass('button-primary-disabled');\", 100);

    Finally, you need to enqeue the script when front pages are loaded, not admin pages. To do this, modify

    add_action('admin_init', 'force_post_cat_init');
    add_action('edit_form_advanced', 'force_post_cat');

    to something like

    add_action('init', 'force_post_cat_init');
    add_action('wp_footer', 'force_post_cat');

    Of course, all due credit goes to the plugin author, so here is the plugin header

    Plugin Name: Force Post Category Selection
    Plugin URI:
    Description: Forces user to assign a category to a post before publishing
    Author: Jatinder Pal Singh
    Version: 0.1
    Author URI:

    Hope this gets you started :slight_smile:


  • matrixd

    Hi again Mort3n your guides are perfect.

    Because I don't know which parameter to use of my Save button I'm senting the code of the button:

    <div class="submit">
    			<input type="hidden" id="_wpnonce" name="_wpnonce" value="3e31859b23" /><input type="hidden" name="_wp_http_referer" value="/members/kiriarxos/classifieds/create-new/" />			<input type="submit" value="Save Changes" name="update_classified">
    			<input type="button" value="???????" onclick="location.href=''">

    I tested with the form ID:
    And works fine except that when you click on the title field popups the alert message!

    Anyway, thanks for great help.


  • mort3n

    Hi matrixd,

    Don't have time to test, so beware :slight_smile:

    Presumably, you have a form with id="cf_update_form" and what you experience is that when you click somewhere on the form, e.g. the title field, the script executes.

    Instead, try with the name of the submit button, something like

    Alternatively, try adding an ID to the submit button and reference that.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.