Support » Fixing WordPress » Globally filtering posts by Custom Taxonomy

  • Hello!

    On our site we want to add the possiblity for the user to choose the content (s)he would like to read about the most. Therefore, I added a simple form which displays all terms of our custom taxonomy (which is assigned to a custom content type).
    Once the user made his/her choice, the term ids are saved in a COOKIE.

    What I need now is a hook to change *all* queries to reflect the user’s preference.


    I have a custom content type called “News”. This content-type has a custom taxonomy called “Flowers”. The taxonomy has different terms (e.g. colours) like: Green, Blue, etc. On the front page the user chose to only see News (the content type) that have the term “Green” assigned to the taxonomy “flowers”. This is now the global setting. Whenever a list of news is being displayed it filters out all entries that do not meet the requirements.

    Is this even possible like that?

    I tried finding some useful info on the “Custom Queries”-Codex page and also checked the pre_get_posts / found_posts hooks/filters to no avail.

    pre_get_posts sounds perfect, but can it work with custom taxonomies?

    Any help is much appreciated. Thanks!

Viewing 1 replies (of 1 total)
  • I have a similar situation, and I have a country texonomy. I have tried add_filter( 'request'.... This does filter out posts on the front page/search, but it does not for example filter out ‘recent posts’ widgets. Hope this might help, and I want to know if there is a way to cover widgets also. So…BUMP THREAD!.

    function alter_the_query( $request ) {
        $dummy_query = new WP_Query();
        $dummy_query->parse_query( $request );
    	$request['tax_query'] = array(
    			'taxonomy' => 'country',
    			'field' => 'slug',
    			'terms' => 'US'
        return $request;
    add_filter( 'request', 'alter_the_query' );
Viewing 1 replies (of 1 total)
  • The topic ‘Globally filtering posts by Custom Taxonomy’ is closed to new replies.