Support » Plugin: A-Z Listing » Display only Child Terms in Custom Taxonomy

  • Resolved gecko_guy

    (@gecko_guy)


    Hi,

    I would like to hide the parents of the terms in a custom taxonomy.

    This is easy to do by modifying the query on line 82 of the plugin file called:

    class-a-z-listing.php

    If I add 'childless' => true, this does what I would like, but I prefer not to modify the plugin files of course, since the change will be lost upon update.

    Is there are hook or function available that I can use to modify that query in my child functions?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Daniel Llewellyn

    (@diddledan)

    Like your request for post-counts I’ll add the ability to alter the taxonomy query via a filter in 2.0.

    Again many thanks! Much appreciated.

    Hi @diddledan,

    I know there is no point asking for a release date, but just wondering if this filter is any closer to becoming available (and also the terms count from my other ticket)?

    Thanks, it will really help a lot.

    Plugin Author Daniel Llewellyn

    (@diddledan)

    You can now filter the taxonomy queries by hooking the filter a-z-listing-query:

    function my_filter_a_z_query( $query, $type ) {
        if ( 'terms' !== $type ) {
            return $query;
        }
        // maybe need some logic to be sure $query is the one you want to change
        $query['childless'] = true;
        return $query;
    }
    add_filter( 'a-z-listing-query', 'my_filter_a_z_query' );

    BWAHAHA! I LOVE YOU DUDE!!

    😉 Kidding, but thanks very much indeed, this will at least avoid the little “hack” I have in place being overwritten upon update.

    I will test it now, many thanks!

    Hey @diddledan,

    Apologies for delayed confirmation. It works.

    I’ll mark this one as resolved, and thanks again.

    Just adding the following for anyone else who stumbles on this thread..

    I had it working in my dev environment, but had a fatal error on the live site because it needs the number of arguments defined.

    So the working code is exactly as suggested, but the add_filter hook should be:

    
    add_filter( 'a-z-listing-query', 'facts_filter_a_z_query',0,2 );
    

    Full error (with personal details removed):

    
    Fatal error: Uncaught ArgumentCountError: Too few arguments to function facts_filter_a_z_query(), 1 passed in .../wp-includes/class-wp-hook.php on line 288 and exactly 2 expected in .../wp-content/themes/child/framework/functions/vendor.php:110 Stack trace: #0 .../wp-includes/class-wp-hook.php(288): facts_filter_a_z_query(Array) #1 .../wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array) #2 .../wp-content/plugins/a-z-listing/classes/class-a-z-listing.php(161): apply_filters('a-z-listing-que...', Array, 'terms') #3 .../wp-content/plugins/a-z-listing/functions/shortcode.php(134): A_Z_Listing->__construct(Array, 'terms') #4 .../wp-includes/shortcodes.php(319): a_z_shortcode_handler(Array, '', 'a-z-listing') #5 [internal function]: do_shortcode_tag(Array) #6 /var/sites/w/wine in .../wp-content/themes/child/framework/functions/vendor.php on line 110
    Plugin Author Daniel Llewellyn

    (@diddledan)

    oops, thanks for picking up my mistake 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display only Child Terms in Custom Taxonomy’ is closed to new replies.