• Resolved 10sexyapples

    (@10sexyapples)


    Hi Scribu, and thanks so much for your work on this. I’ve really been struggling with a solution for a site I’m developing that needs complex drill down filtering. It’s a site that provides lesson plans to teachers helping to integrate the arts into education.

    The entire meat of the site is comprised primarily of 3 custom post types – lessons, howtos and workshops and a multitude of custom taxonomies representing subject matter of the above … ie art, academic, standard, grade etc.. I would love to use this code, but, I’m having a few issues that I hope you can help me out with:

    I tried to change the post type in the widget to one of my custom ones to have it recognize the taxonomies, and it did recognize all of them, but, the queries don’t work, so, I’m missing something.

    I’ve created a page and am using a custom template to call in all of the posts from my custom post type ( makeshift archive ), and would like to do the drill down in the sidebar of this page ( the lessons will be shown in grid form ) so initially when you go to lessons, it will be a complete paged archive, but, as you drill down it gets more specific and the grid shifts accordingly.

    I’m not even sure that this will work without some sort of redirect, or maybe that is what your multitax template is for and I just didn’t get it.

    Any help at all getting through this jungle of confusion would be greatly appreciated.

    Thank you!!

Viewing 15 replies - 1 through 15 (of 21 total)
  • To make it work with a custom post type, add this code in your theme’s functions.php file:

    function my_qmt_post_type() {
        return 'lesson';
    }
    add_filter('qmt_post_type', 'my_qmt_post_type');
    Thread Starter 10sexyapples

    (@10sexyapples)

    You rock! Thanks so much for responding! I was also curious about two other things if you have a chance to respond … 1. If it’s possible to call function for the widget directly in a non-widgetized sidebar and 2. If it causes any issues calling multiple instances of the function, one for each taxonomy, in one sidebar. Again, I’m thinking that perhaps this is where I would use the multi-tax template? Should I be using the multi-tax template fitted with a custom query for the post type “lesson” in order to have the results of the drill down always remain on the same page? The goal of course being to drill down the custom post type of lesson through all of the custom taxonomies ( art subject, academic subject etc. ) and always remain on the same page. Hope I’m not asking too much ??

    1. If it’s possible to call function for the widget directly in a non-widgetized sidebar

    See the_widget()

    2. If it causes any issues calling multiple instances of the function, one for each taxonomy, in one sidebar.

    It doesn’t cause any issues: it’s a multiinstance widget for multiple taxonomies. ??

    Should I be using the multi-tax template fitted with a custom query for the post type “lesson” in order to have the results of the drill down always remain on the same page?

    Not sure what you mean by “on the same page”. The URL will change depending on what the user clicks.

    If you use multitax.php, you don’t need to use query_posts() or new WP_Query(). Use a normal loop, like in index.php.

    Thread Starter 10sexyapples

    (@10sexyapples)

    Thank you for the info on the_widget function … I can’t keep up with you guys ?? Sometimes I write questions long after I have the mental capacity to even understand what I’m asking, so, sorry for the vague weirdness.

    I played around with everything, got the widget function and the multitax template going, so that is all good.

    My previous confusion was in regards to the fact that there really is no way, that I have found … yet … to have a menu item ( page ) that lists custom post types in an archive fashion, without having to set a page template that queries for the custom post type.

    Let me digress for a moment as it would probably help to know my goal, which is to have a menu item called “lesson plans” that when clicked has all lesson plans ( lesson is a custom post type ) in archival fashion. In the sidebar of that page is the drill down custom taxonomies that have been assigned to lesson plans ( art subject, academic subject, grade, etc. ). I was unclear at first how the multitax template would function, as in, if it would “appear” to still be the same page, only drilled down by the selections of the custom taxonomies.

    That said, I have experimented with the template and it does behave in the way that I need it to. I can’t stand the hackiness of not being able to have something like an archive.php for my custom post type, but, I will probably need to stick with the “illusion” of an archive for now … darnit.

    My question about the multiple instances was just as vague and improperly stated, so let me apologize and elaborate on that as well. I was referring to being able to drill down through all of the multiple instances of the drill down widgets ( gee that was way more specific huh? ?? ). Now, from what I understand, from what you’ve said above, and from the title “query multiple taxonomies” I was under the impression that that is exactly what I should be able to do, but, the way that it is behaving, on my page at least, is that I am able to drill down in one taxonomy widget at a time, but, not in multiple ones.

    Example:
    I have an art subject taxonomy, which contains terms like theatre, music, dance etc., and an academic subject taxonomy which contains terms like math, science, history etc..
    If I click the plus on theatre and then on music, I will get the =theatre+music, but, if I then click on science, it will give me =science only. I am not getting the function of art=theatre+music AND academic=science.

    Perhaps I am doing something wrong? I hope my long-winded-ness made a little bit of sense. My apologies if it sounds like I am talking gibberish again.

    Thanks again for all the hard work too!!

    I have an art subject taxonomy, which contains terms like theatre, music, dance etc., and an academic subject taxonomy which contains terms like math, science, history etc..
    If I click the plus on theatre and then on music, I will get the =theatre+music, but, if I then click on science, it will give me =science only. I am not getting the function of art=theatre+music AND academic=science.

    That looks like a bug in the plugin. If you’re willing to let me do some debugging on your site, send me an email: [email protected]

    Thread Starter 10sexyapples

    (@10sexyapples)

    Email sent ??

    Thread Starter 10sexyapples

    (@10sexyapples)

    I made this little change in order to get the url to return to the custom post type that it came from. It’s pretty hacky but, it gets the job done.

    function get_canonical_url() {
    	$post_type = apply_filters('qmt_post_type', 'post');
    		if ( empty(self::$url) )
    			self::$url = add_query_arg(self::$actual_query, get_bloginfo('url') . '/' . $post_type . 's' );
    
    		return self::$url;
    	}

    I know there is a better way to do this, especially getting the plural of the post type, but, alas, I’m still not strong enough in PHP to know the right way. ??

    There is no plural (slug) for a post type, unless you define it yourself, so it’s ok.

    In the latest development version (1.2-alpha4), you can do this instead:

    function my_qmt_base_url($base) {
    	$post_type = QMT_Core::get_post_type();
    
    	return get_bloginfo('url') . '/' . $post_type . 's';
    }
    add_filter('qmt_base_url', 'my_qmt_base_url');
    Thread Starter 10sexyapples

    (@10sexyapples)

    Hi Scribu,
    Cool, you’ve set up a filter for a base url, that’s just what I needed. I do have plurals set up for my post types, I just wasn’t sure exactly how to call it in. I can’t just call it in this function with :

    $post_type = QMT_Core::get_post_type(post_type->label); can I? Don’t I need to use $post_type = get_post_type_object(post_type->label);?

    I was also curious with these two filter functions that you’ve given me here how to return more than one post type. Can I return an array of post types here?

    `function my_qmt_post_type() {
    return array(‘lesson’, ‘howto’, ‘workshop’);
    }
    add_filter(‘qmt_post_type’, ‘my_qmt_post_type’);’

    The base url function will get the post_type from the query var that is already in the url from my rewrite code that has created the custom post type “archives” I’m assuming, and will change depending on whether it is coming from lessons, howtos, or workshops?

    I think my logic may be a little twisted right now, so, I’m going to go do a little experimenting to figure this out. I’ll report back~

    Cool, you’ve set up a filter for a base url, that’s just what I needed. I do have plurals set up for my post types, I just wasn’t sure exactly how to call it in. I can’t just call it in this function with :

    $post_type = QMT_Core::get_post_type(post_type->label); can I? Don’t I need to use $post_type = get_post_type_object(post_type->label);?

    $ptype = get_post_type_object(QMT_Core::get_post_type());
    $plural = sanitize_title_with_dashes($ptype->label);

    You could also set a new property, like query_var_plural instead of label.

    I was also curious with these two filter functions that you’ve given me here how to return more than one post type. Can I return an array of post types here?

    Currently, no; a single post type is allowed. I’m still thinking of a better way to handle this.

    Thread Starter 10sexyapples

    (@10sexyapples)

    Excellent Scribu. And thanks again.

    You’ll have to excuse my ignorance sometimes when it comes to certain things. I come from a 14 year background as a publisher/network administrator/yadda yadda all that that entails, and have only begun teaching myself all of this area ( PHP, MySQL, Javascript, CSS, Html ) in the last two years. I did start to learn Basic back in college … like in 1986! …. ha!, and loved it, and I learn fast, but, it is a pretty big chunk to swallow in such a short time, so sometimes it sounds like I know what I’m talking about, and sometimes I sound like a complete idiot ;-).

    I’m reading and learning all the time, but, still have soo far to go. That said, here’s where the idiot part comes in. I have no idea what it means “exactly” to set a new property. I understand in an ambiguous “theory” sort of way, but, don’t really comprehend what purpose would be served by doing it, or exactly how it would be accomplished “code wise”.

    I’ve looked through your code on quite a few things you’ve written and it seems that you write with a really clean, well-thought out, methodology and that you use very up to date techniques. I will definitely be trying to learn and emulate from your style~

    On the multiple post types. Since you use the QMT_Core class, I’m thinking, for now, I could probably duplicate and make three versions using something like QMT_Core_Lesson, QMT_Core_Howto and QMT_Core_Workshop in order to have the functionality for each post type and it’s archive individually?

    I have no idea what it means “exactly” to set a new property. I understand in an ambiguous “theory” sort of way, but, don’t really comprehend what purpose would be served by doing it, or exactly how it would be accomplished “code wise”.

    Now that I think about it, it’s not that obvious:

    register_post_type('lesson', array(
        ...
        'query_var_plural' => 'lessons'
    ));
    
    ... later ...
    
    $ptype = get_post_type_object(QMT_Core::get_post_type());
    $plural = $ptype->query_var_plural;

    I’ve looked through your code on quite a few things you’ve written and it seems that you write with a really clean, well-thought out, methodology and that you use very up to date techniques. I will definitely be trying to learn and emulate from your style~

    Thanks ??

    On the multiple post types. Since you use the QMT_Core class, I’m thinking, for now, I could probably duplicate and make three versions using something like QMT_Core_Lesson, QMT_Core_Howto and QMT_Core_Workshop in order to have the functionality for each post type and it’s archive individually?

    You’ll have a hard time doing that, since the QMT_Core class name is hardcoded throughout the plugin.

    Rather, you could try setting the post type based on the $_GET variables. Something like this:

    function my_qmt_post_type() {
      if ( isset($_GET['grade']) )
        return 'lesson';
      elseif ( ... )
    }
    Thread Starter 10sexyapples

    (@10sexyapples)

    Hey, wait a minute, since I should already have the post_type in the $_GET because the page I will currently be on will be the plural of the custom post type archive, couldn’t I use

    function my_qmt_post_type() {
      if ( isset($_GET['lessons']) )
        return 'lesson';
      elseif ( ... )
    }

    If I’m getting my GETs right, That will tell it which custom post type archive I am on and therefore which custom post type posts to be filtering right? Or am I missing something? … probably missing something.

    Well, last but not least, the hack. You’ve never seen me go with my search and replace functions ??
    14 years of magazine editing doesn’t hurt either.

    After a couple weeks straight of trying to figure out how to make a certain unnamed related posts plugin conditionally separate out my post types with no success, and no help … but lots of attitude from the developer, and clumps of hair all over the floor around me. I was left with no choice but to split it into three plugins to do the job. … heh, yeah, I know, I’m su-per funny right?

    Hey, wait a minute, since I should already have the post_type in the $_GET because the page I will currently be on will be the plural of the custom post type archive, couldn’t I use

    Rather than asking me about it, you should just try it and see if it works.

    You can use this to see what’s in the $_GET variable: print_r($_GET).

    Thread Starter 10sexyapples

    (@10sexyapples)

    Well, turns out the $_GET didn’t work, nor did several other options that seemed like they should, what did finally work was this-

    if ( get_query_var('post_type') === 'lesson' ) {
    return 'lesson';

    yay!!

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘[Plugin: Query Multiple Taxonomies] Recognize Custom Taxonomies registered only to Custom Post Types’ is closed to new replies.