logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Ajax Category Dropdown Plugin change, need to Exclude Category

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

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.



This question has been answered.

Luke Pickett | 11/17/10 at 8:16am Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    11/20/10
    11:27pm
    John Cotton says:

    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

    • 11/17/10 8:57pm

      Luke Pickett says:

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

    • 11/17/10 9:00pm

      John Cotton says:

      Can you post the code that you've changed?

    • 11/18/10 8:26am

      Luke Pickett says:

      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?

    • 11/18/10 8:37am

      John Cotton says:

      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).

    • 11/19/10 8:00am

      Luke Pickett says:

      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?

    • 11/19/10 9:50am

      John Cotton says:

      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.

  • avatar
    Last edited:
    11/18/10
    12:38pm
    Pippin Williamson says:

    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";

    • 11/19/10 8:01am

      Luke Pickett says:

      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.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.