WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
Search a single Custom Post Type (7 posts)

  1. KhidhaBoy
    Member
    Posted 4 years ago #

    Hi right n00b to wordpress here.

    First of, Scribu this is an excellent plugin and pretty much does 80-90% (maybe more) of what I need. My scenario is I have 3 Custom Post types (post, case-studies & resources). They all share the same taxonomies (subject, sector, age-range).

    What I need to achieve is present the widget on three separate pages (post, case-studies & resources) and thus when the user builds up the taxonomy filters it just pulls back results for the appropriate post type. Kinda like a dedicated Case Studies filter page and a dedicated Resources filter page.

    I tried this on my functions.php file but doesn't seem to do anything

    function my_qmt_post_type() {
    return 'resources';
    }
    add_filter('qmt_post_type', 'my_qmt_post_type');

    b.t.w I'm using version 1.2.3 of the plugin.

    many thanks

    KB

  2. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    First of all, you will have to switch to the development version (1.3-alpha7).

    Then, just add this code to your functions.php:

    function my_qmt_url($url) {
    	// post type => associated page slug
    	$map = array(
    		'post' => 'posts',
    		'case-study' => 'case-studies',
    		'resource' => 'resources'
    	);
    
    	foreach ( $map as $post_type => $page_slug ) {
    		if ( is_page( $page_slug ) ) {
    			$url = add_query_arg( 'post_type', $post_type, $url );
    			break;
    		}
    	}
    
    	return $url;
    }
    add_filter( 'qmt_url', 'my_qmt_url' );

    Of course, you can customize the $map variable to match your page slugs etc.

  3. KhidhaBoy
    Member
    Posted 4 years ago #

    Thanks, will give that a go.

    I've started to think my content might be better organized using Categories rather than Custom Post Types.

    So how about (similar principle as above) but filtering within "Categories"?

    Many Thanks

  4. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    Just replace post_type with category_name.

  5. KhidhaBoy
    Member
    Posted 4 years ago #

    Just downloaded the development version, very nice the way list items work - in the previous version I had to add the widget X number of times.

    Just a thought, I noticed with both drop-down and list items, when you select one it filters the results and tells you what filter you've picked, but if you select more than one it just says "Posts classified under": filter X.

    It would be cool if it could list the filters you've selected. If that makes sense

  6. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    Just a thought, I noticed with both drop-down and list items, when you select one it filters the results and tells you what filter you've picked, but if you select more than one it just says "Posts classified under": filter X.

    That's probably something your theme is doing. You can extend it to display multiple filters by using qmt_get_query().

  7. NaomiA
    Member
    Posted 3 years ago #

    Hi there,
    I have similar query but am working on current version. How do I use the widget to search only one post type, and not all?
    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic