Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Ajax Category Dropdown Plugin change, need to Exclude Category WordPress

  • SOLVED

Hi, I'm look for a small change to the Ajax Category Dropdown Plugin ([[LINK href="http://wordpress.org/extend/plugins/ajax-category-dropdown/"]]http://wordpress.org/extend/plugins/ajax-category-dropdown/[[/LINK]]).

I want to be able to exclude categories from the dropdown boxes, right now it pulls all the categories with no option to exclude. I'm not sure what else to add, I think it would be fairly straight forward to do. Let me know if you have any questions.



Answers (2)

2010-11-17

John Cotton answers:

Hi Luke

On line 71 of dhat-ajax-cat-dropdown-request.php there's a query:


$cat_query = "SELECT * FROM $wpdb->terms
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
WHERE $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.parent = $main_cat
ORDER BY $sort";


You'd need to add something like:
AND $wpdb->terms.term_id NOT IN (XXXX)

with XX replaced by whatever you want to exclude.

To make that XX dynamic, you'd have to add an option(s) to the settings page - difficult to describe here as it means changes in several places in that code.

John


Luke Pickett comments:

Hi, that didn't seem to work it just made the plugin stop functioning, thoughts?


John Cotton comments:

Can you post the code that you've changed?


Luke Pickett comments:

Hi,

If I enter the number of the category (below), nothing happens.
$cat_query = "SELECT * FROM $wpdb->terms
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
WHERE $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.parent = $main_cat
AND $wpdb->terms.term_id NOT IN (169)


And if I enter the actually name of the category (below) the plugin doesn't pull any of the secondary categories.
$cat_query = "SELECT * FROM $wpdb->terms
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
WHERE $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.parent = $main_cat
AND $wpdb->terms.term_id NOT IN (accommodation)


Any ideas?


John Cotton comments:

Well the first one will work...providing the term with id 169 has a parent with id $main_cat. If not then it wouldn't appear anyway (is it in the list?)

The 2nd set of code won't work for several reasons, not least that you need to delimit the string (and term_id is actually an integer).


Luke Pickett comments:

The category ID is 169, I cut and pasted the edited page URL below if that helps.
wp-admin/edit-tags.php?action=edit&taxonomy=category&post_type=post&tag_ID=169

So far neither solution has removed category 169 from the dropdown menu. It either does nothing, or stops the plugin from proceeding to the next box, stalling on the first box, with the category that I'm trying to remove still in it. Thoughts?


John Cotton comments:

I think I've misunderstood the question...

Is the category you want to exclude one that appears in the dropdown when the page loads? ie not via AJAX?

If yes, then it's code in dhat-ajax-cat-dropdown.php that needs editing.

There are 3 queries from line 845 onwards (it's not very nice code...)

Adding

AND $wpdb->terms.term_id NOT IN (169)

just after

AND $wpdb->term_taxonomy.parent =

should do the job.

2010-11-18

Pippin Williamson answers:

Try this:


$cat_query = "SELECT * FROM $wpdb->terms
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
WHERE $wpdb->term_taxonomy.taxonomy = 'category'
AND ($wpdb->term_taxonomy.parent = $main_cat && $wpdb->terms.term_id NOT IN (169))
ORDER BY $sort";


Luke Pickett comments:

Hi that didn't seem to work, I've replied to the above answer maybe that'll give you a little more help in figuring this out? Cheers.