How do I add a relation parameter to my filter query?

Each of your code blocks will overwrite the previous, you need to add to the array rather than replace it: $args[‘tax_query’][] = array( ‘taxonomy’ => ‘region’, ‘field’ => ‘id’, ‘terms’ => $_POST[‘region_filter’] ); relation is AND by default, so you can just omit it, but if you wanted to explicitly set it: $args[‘tax_query’][‘relation’] = ‘AND’;

WP_Query returns no posts for category

The issue turned out to be custom post types. Even though a custom post type produces posts, WP_Query() doesn’t select them unless specifically coded to do so with ‘post_type’ => ‘slug’, in the query arguments.

Grabbing taxonomy terms and inserting them into an array

This creates the multidimensional array in advance and then assigns it to options. The multidimensional array is created by assigning an array to each element of the main array. I have reused the $feat_pages_terms variable, but you can also create a separate variable using array() and assign array elements to that, I am including those … Read more

WP_Query by keyword OR post tag

Depending what you want to achieve, the most simple way taken from WordPress documentation looks like below. Displays posts tagged with “bob”, under “people” custom taxonomy: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’, ), ), ); $query = new WP_Query( $args ); Check … Read more

Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?

I think you need first to sort the genre terms in the other query: $genres = get_terms( ‘genre’, ‘orderby=term_id’ ); And then on the posts query for each genre (like Chip Bennet’s approach): $member_group_query = new WP_Query( array( ‘post_type’ => ‘member’, ‘orderby’ => ‘name’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘member_group’, ‘field’ => ‘slug’, ‘terms’ … Read more

How can I comment comma-separated array values?

No, it’s definitely not okay to comment your code this way. It changes the string, and even though WordPress might strip the incorrect characters and yield the correct pages (it wouldn’t if your “comments” contained comma’s or numbers), it is incredibly unstable. Instead, if you do want to comment them, I would suggest storing them … Read more

pre_get_posts – editing query, tax_query

So there’s a few things wrong with the code: You’re not using the query object that’s passed to the pre_get_posts hook, so you’re not modifying the actual query. Field is set to id instead of term_id. If you’re using IN as the operator, pass an array to terms. You’re not sanitizing the value of $_POST[‘networks’]. … Read more