Support » Plugin: Query Multiple Taxonomies » Make empty queries filter automatically by custom post type of archive

  • Hello fellow wordpress users,

    I have a series of dropdowns on each of my custom post type archives. I want to set up the site so that if none of these dropdowns are set, or even if they are, the base URL of the query string limits results to that particular post type. So on the resource archive, the query string will be “example.com/post_type=resource&topic=bananas&timeline=” while in the animation archive, the query string will be “example.com/post_type=animation&topic=bananas&timeline=”

    Still struggling but after a few hours I think that this code looks close to what it should… though it still doesn’t work!

    function my_qmt_base_url() {
    	if (is_post_type_archive()) {
    		$CPTquery = get_post_type( $post->name );
    }
        return add_query_arg( 'post_type', $CPTquery );
    }
    add_filter( 'qmt_base_url', 'my_qmt_base_url' );

    I’m just not sure if I’m calling the post_type name properly, because this code doesn’t seem to affect my URL… Though I have tested it with “return ‘TEST’;” and that does affect the URL properly. As it stands, post_type is just not included in the query string.

    Any help is much appreciated.

    http://wordpress.org/extend/plugins/query-multiple-taxonomies/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter thhhhh

    (@thhhhh)

    I’ve tried arranging the code in a number of different ways… currently:

    function my_qmt_base_url( $url, $CPTquery ) {
    	if ( is_post_type_archive ()) {
    		$CPTquery = get_post_type( $post->slug );
    }
    $url = '?post_type='.$CPTquery.'&';
        return $url;
    }
    add_filter( 'qmt_base_url', 'my_qmt_base_url' );

    The results are the same and I don’t see “?post_type=whatever” in my query string. I’m not sure this is a problem with calling the name of the post type, because I can set up the above code with $url = ‘TEST?post_type=’ and I will get a URL which looks like “example.com/TEST?resource_type=&topics=&timeline=”. If I set $url as a fixed value, like ‘?post_type=resource’, it does not affect the URL at all. The code seems to refuse to relay anything after the question mark before post_type. Any ideas?

    I am looking for this too…did you ever figure it out?

    Thread Starter thhhhh

    (@thhhhh)

    joshuaiz,

    Haven’t figured it out yet but I’m back at it again. Will let you know.

    I would also like to be able to do this… thhhhh, Did you come to a conclusion?

    Thread Starter thhhhh

    (@thhhhh)

    Not yet. I am consistently able to get the function to change the front of the url I generate, such as adding “people” to “example.com/people/?topics=studios”

    What I want to do is to add “/?post_type=people&” to the front of my urls. I’ll let everyone know if there are any developments.

    Thread Starter thhhhh

    (@thhhhh)

    Alright, is it just me, or does the my_qmt_url function not do anything at all? Described here: https://github.com/scribu/wp-query-multiple-taxonomies/wiki/Changing-URLs

    hey @thhhhh, did you manage to attach “&post_type=xx” to the urls?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Make empty queries filter automatically by custom post type of archive’ is closed to new replies.