• Hi there

    On my homepage I have a list of categories which when clicked will show all the posts from that specific category. I have also used a custom filter on the homepage to showcase specific categories.

    What I would like to do is, when someone clicks to view a specific cateogory, that result list would be filtered though the same specific categories as shown on the showcase.

    For example, I have a list of farmers and one of the categories that they have is gender, so I might filter them to show only women farmers on the homepage showcase. Also on the homepage I have a list of all other categories that a farmer might below to eg crop. Now when a user clicks on the catergory eg “bananas”, then I want only the women banana farmers to show and not all the farmers.

    As the showcase filter is always changing I cannot hard code this so have to send this information (which I am doing using a session variable) so I can retrieve the fact that I just want the women to show but am stuck with trying to show a combination of eg “women and bananas” on the category result page.

    Hope that makes sense and any help would be greatly appreciated.

    Warm regards
    Denise

Viewing 2 replies - 1 through 2 (of 2 total)
  • You should be able to do what you want using a tax_query.

    Assuming that ‘farmers’ is a custom post type, the category slug from the session variable is in $cat1, and the user clicked category slug is in $cat2, this should work:

    $args = array(
    	'post_type' => 'farmers',
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => $cat1
    		),
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => $cat2
    		)
    
    	)
    );
    $query = new WP_Query( $args );
    Thread Starter dcmd08

    (@dcmd08)

    Thanks that worked Awesome!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter query results’ is closed to new replies.