WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
Make empty queries filter automatically by custom post type of archive (8 posts)

  1. thhhhh
    Member
    Posted 1 year ago #

    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/

  2. thhhhh
    Member
    Posted 1 year ago #

    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?

  3. joshuaiz
    Member
    Posted 1 year ago #

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

  4. thhhhh
    Member
    Posted 1 year ago #

    joshuaiz,

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

  5. mattyrogers84
    Member
    Posted 1 year ago #

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

  6. thhhhh
    Member
    Posted 1 year ago #

    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.

  7. thhhhh
    Member
    Posted 1 year ago #

    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

  8. rafael.slonik
    Member
    Posted 11 months ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.