WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
[resolved] WP3.01 QMT1.3.1 Canonical Redirect and post_type query var (8 posts)

  1. 10sexyapples
    Member
    Posted 4 years ago #

    Previously, in QMT1.3alpha7, a click on "add term" directed me to the taxonomy.php template, but, allowed me to then use conditional calls within that template like this:

    <?php /*-------LESSON based taxonomy------*/?>				
    
    <?php if ( get_query_var('post_type') == 'lesson' ) { ?>
    
    <?php echo ('<h1 class="page-title">Lessons Filtered</h1>'); ?>
    
    //Stuff removed for simplicity
    
    <?php include( STYLESHEETPATH . '/sidebar_grid_drill_lesson.php' ); ?>

    to separate out my custom post type results.

    In 1.3.1, a click still directs me to the taxonomy template, but, the post_type query var is no longer active, so, it is bypassing my conditionals and going straight to the default styling for normal post taxonomies.

    I've implemented the canonical redirect filter, which is fantastic and keeps me on the original custom archive template I've created, but I lose the "filtered" styles I've implemented on the taxonomy template, so, ultimately, would prefer that it did go ahead and redirect to the taxonomy template if possible.

    Is it possible to use the canonical redirect while retaining the post_type in the query var like it was way back when in 1.3alpha7?

    Sorry for being such a PITA eh? Feel free to tell me to get a grip and just deal with it ;-) It is some darn pretty code and so incredibly valuable. I know how hard and long you've worked on this functionality, so, on a serious note ... Thank You so MUCH Scribu!

  2. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    Tell me what you get when you run this code:

    function qmt_debug() {
      global $wp_query;
    
      echo '<pre>';
      print_r($wp_query->query);
      print_r($wp_query->_qmt_query);
      var_dump($wp_query->_qmt_is_reqular);
      echo '</pre>';
    }
    add_action( 'template_redirect', 'qmt_debug', 8 );

    Also the URL.

  3. 10sexyapples
    Member
    Posted 4 years ago #

    Darn. I didn't see your message before, sorry for the delay~

    Url:
    http://cotaprogram.org/cotadev/lessons

    Debug:

    Array
    (
        [post_type] => lesson
    )
    Array
    (
    )
    bool(true)

    url:
    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    Debug:

    Array
    (
        [post_type] => lesson
        [grade] => grade-one
        [taxonomy] => grade
        [term] => grade-one
    )
    Array
    (
        [grade] => grade-one
    )
    bool(true)

    Well, looking at this, I'm thinking that perhaps it is the rewrite rules for my custom_post_type that are directing this?

  4. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    The rewrite looks good.

    So you're saying that on http://cotaprogram.org/cotadev/lessons?grade=grade-one, in taxonomy.php, get_query_var('post_type') doesn't return 'lesson'?

    What do you get instead?

  5. 10sexyapples
    Member
    Posted 4 years ago #

    Okay, I'm an idiot. I forgot where I was at in the midst of everything, and the info that I was giving you above was with the canonical redirect canceled, which, of course, returns accurately.

    Here is the info of what happens with canonical redirect in place. The goal being of course to click on a term, have it redirect to the taxonomy.php template, whereabouts it gets a conditional styling pending the post_type query var.

    url:
    http://cotaprogram.org/cotadev/lessons

    Type-Lesson.php Debug:

    Array
    (
        [post_type] => lesson
    )
    Array
    (
    )
    bool(true)

    url:

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    Taxonomy.php Debug:

    Array
    (
    [post_type] => lesson
    [grade] => grade-one
    [taxonomy] => grade
    [term] => grade-one
    )
    Array
    (
    [grade] => grade-one
    )
    bool(true)

    Warning: Cannot modify header information - headers already sent by (output started at /home/cotapr5/public_html/cotadev/wp-content/themes/cota/functions.php:583) in /home/cotapr5/public_html/cotadev/wp-includes/pluggable.php on line 890

    I used your debug to take a look at what's returning for the author.php page as well, just to see if I could round up another clue as to why I am getting illegal offset warnings there when trying to get the custom post types into the query, and I get the same modify header warning on that page as well. These are the only two pages that I am getting this warning, so, I'm going to turn off all plugins except QMT right now and see if one of them is causing this. I know there are no spaces or anything that would typically cause this at the end of my functions file.

    I'll report back in a bit.

  6. 10sexyapples
    Member
    Posted 4 years ago #

    Okay, I turned off all plugins, and the result was the same.

    I did notice however, probably unrelated, but, when I have the QMT debug code activated and I click on an authors name/link the resulting url is http://cotaprogram.org/cotadev/author/danielle/ and that is where I get the headers already sent error.

    If I remove that code, and hover over an authors name, it shows the url the same as above, but, when clicked the url that is returned is http://cotaprogram.org/cotadev/author/danielle and there is no error.

    I also found that the code that I am using to create the custom post type archives is the offending code causing the illegal offset errors when trying to implement the code below for injecting custom post types into author.php ... you may recognize it from mine and Krusty Tuffles topics regarding pre_get_posts etc. on the hacker's list ...

    // Get custom post types into loops
    function my_request ( $request ) {
    // Check for proper indexes. An empty $request means we are on the main blog index.
         if ( empty ( $request ) || isset ( $request['author_name'] ) || isset ( $request['year'] ) )
         $request['post_type'] = array ( 'lesson','howto' ); //Modify the $request
         return $request;
    }
    add_filter ( 'request', 'my_request' );

    I'm going to disable the code that is creating my custom post type archives and will report back again with the results of the QMT debug~

  7. 10sexyapples
    Member
    Posted 4 years ago #

    Alright, here are the results with the custom post type archive code removed.

    With

    //QMT: Cancel Canonical Redirect---------------------------//
    function cancel_redirect_canonical( $redirect_url ) {
        if ( is_tax() )
            return false;
    
        return $redirect_url;
    }
    add_filter( 'redirect_canonical', 'cancel_redirect_canonical');

    active in my functions file, and this url in the browser

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    I get the proper response of the taxonomy.php template being used, and the post_type query vars conditional being respected. This is the expected behavior. yay.

    If I then remove the cancel_canonical_redirect, and put in the same url,

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    The url redirects to this

    http://cotaprogram.org/cotadev/grade-level/grade-one

    and the taxonomy.php template is still used, but, this time with the query var conditionals not being respected.

    I will now do the same test with the debug code active:

    cancel_canonical_redirect is active and debug code is active

    url is http://cotaprogram.org/cotadev/lessons?grade=grade-one

    I get the same result as above with the taxonomy.php template being used and post_type query var conditionals being respected

    Debug message is:

    Array
    (
        [post_type] => lesson
        [grade] => grade-one
        [taxonomy] => grade
        [term] => grade-one
    )
    Array
    (
        [grade] => grade-one
    )
    bool(true)

    and now with the cancel_canonical_redirect removed and debug code active,

    same url

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    url stays this:

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    and I get a blank page with this debug message:

    Array
    (
        [post_type] => lesson
        [grade] => grade-one
        [taxonomy] => grade
        [term] => grade-one
    )
    Array
    (
        [grade] => grade-one
    )
    bool(true)

    Warning: Cannot modify header information - headers already sent by (output started at /home/cotapr5/public_html/cotadev/wp-content/themes/cota/functions.php:585) in /home/cotapr5/public_html/cotadev/wp-includes/pluggable.php on line 890`

    Well, this is really scrambling my brain. I hope, actually, I'm sure, all of this makes perfect sense to you and I've probably given you a whole crazy load more info than you actually needed to see what's happening, but, I guess better safe than sorry.

    The array error is still there when a term is clicked as well, I don't know if that has any relation to this:

    I'll send a screenshot of that if you want me to~

    I guess the end goal, if I can clear my head enough to remember the goal, is to end up with this url:

    http://cotaprogram.org/cotadev/lessons?grade=grade-one

    becoming this

    http://cotaprogram.org/cotadev/lessons/grade-level/grade-one

    using the taxonomy.php template with the post_type query var still being respected to allow for the template to show only the taxonomy results and styling for that specific post type.

    base url with no terms goes back to http://cotaprogram.org/cotadev/lessons

    Wow. I really wished that the custom_post_type archive template had made it in to 3.01, I know there is a ticket in, so waiting with baited breath. This has been such a ball of twine to unravel ;-)

    If I can get this worked out, then, I still need to figure out why the custom archive code is causing the illegal offset errors.

    Thank you for your patience with me Scribu. I know it must get annoying~

  8. 10sexyapples
    Member
    Posted 4 years ago #

    Well, at least part of this is beginning to make sense.

    Without my custom post type archive code active,
    and with my cancel_canonical_redirect active,

    I get the taxonomy.php template, properly styled, with one or more terms added to the filter.

    With the custom post type archive code activated,

    I get the custom_post_type archive.php template when one term is clicked/added to the filter,

    and the taxonomy.php template, when a second or more filter is added.

    This confirms, at least to me, that not only is my illegal offset issue coming from this code, preventing my request filters from working, but, the rewrites are obviously also interfering with the QMT rewrites.

    Geesh. Okay, off to figure this out~

    Sorry for wasting your time on this issue, as this obviously doesn't even have anything to do with what QMT is doing. Argh.

    Aside from that little array bug, QMT is functioning beautifully and again I want to say thanks for that.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic