Support » Plugin: Smart Archives Reloaded » [Plugin: Smart Archives Reloaded] Custom Taxonomies

  • Resolved Doodlebee

    (@doodlebee)


    Just a question: I have this working nicely with custom post types. However, I want to show results ONLY for a single specific category (a custom taxonomy for the custom post type) – but cannot make it work.

    Usually I use Otto’s advanced custom taxonomy query tutorial, but apparently the query within the plugin doesn’t allow me to access the tax_query to make that specification in the manner presented by Otto.

    So I’m kind of stumped. Is there a way I can add some sort of filter to the regular query this plugin uses so I can pull this off?

    Thanks so much 🙂

    http://wordpress.org/extend/plugins/smart-archives-reloaded/

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

    (@scribu)

    How are you passing the custom post type to the query?

    That’s the question, what I’m trying isn’t passing it. So far, I’ve got this, but I’m pretty sure I’m going about this the wrong way:

    class SAR_Custom_Generator extends SAR_Generator {
    
     protected function generate_fancy() {
    	function custom_tax_filter($query) {
       		 $query->set('tax_query', array(
                'relation' => 'AND',
                array(
                      'taxonomy' => 'author_category',
                      'field' => 'slug',
                      'terms' => 'campaigns'
                      )
                )
               );
              return $query;
    	}
    	add_filter( 'pre_get_posts', 'custom_tax_filter' );
     }
    
    }

    ’cause it’s totally not doing anything at all. (I think it’s probably in the add_filter section, mainly because I think this needs to happen before when I’m calling it, if that makes sense). I’m still playing with it to see what’s happening.

    Plugin Author scribu

    (@scribu)

    You can pass query params directly to the smart_archives() template tag:

    <?php smart_archives( '', array(
      'tax_query' => array(
        ...
      )
    ) ); ?>

    Yes! That’s what I originally tried (it made the most sense) but it wasn’t working. here’s what I had before I tried the magled stuff above:

    $query = array('orderby' => 'author',
    			  'post_type' => 'author_posts',
    			  'tax_query' => array('taxonomy' => 'author_category',
    					    		  'terms' => 'campaigns',
    					    		  'field' => 'slug'
    					    		  )
    			);
    
    smart_archives('format=fancy', $query);

    it seems it doesn’t mix well. if I leave off the “orderby” and “post _type”, and just stick with the tax_query, it returns regular posts (but why, I have no idea, since there are no regular posts using the custom taxonomy); but if I leave off the tax_query, it’ll return all the author_posts (custom post type) – which is what it should do – but I also need it to only return the custom post type that’s in that custom taxonomy.

    Plugin Author scribu

    (@scribu)

    Does calling WP_Query directly with those parameters return the correct posts?

    ah, excellent test – thank you. And no, it’s not returning the correct stuff – so something’s gotta be wrong with my syntax…

    Oh wow. it was WAY easier than I thought! Here’s what works:

    smart_archives('format=fancy', array('orderby' => 'author',
    				'post_type' => 'author_posts',
    				'author_category' => 'campaigns'
    			)
    		);

    Hope that helps someone else 🙂

    Plugin Author scribu

    (@scribu)

    Yeah, the problem was that you were missing a level of array nesting inside ‘tax_query’, but ‘tax_query’ doesn’t make much sense for a single taxonomy anyway.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Smart Archives Reloaded] Custom Taxonomies’ is closed to new replies.