You will find the Codex Action Reference handy – while it doesn’t list everything, it gives a good overview of action order which can help locate the correct action if the one you’re using runs too late.
In your case, wp
does indeed run after the query is run, but looking at that list it appears – depending exactly on what logic you’re wanting to run – that pre_get_posts
would be a good choice for you. This is actually a commonly used action that, quite powerfully, allows you to modify almost anything about the query before it runs.
Not seeing your code it’s a little difficult to anticipate exactly what you want this to perform, but I am guessing you’re after something like this:
add_action( 'pre_get_posts', 'wpse202063_photographs_term' );
function wpse202063_photographs_term( $query ){
if( ! is_admin() && $query->is_main_query() && is_singular( 'product' ) ){
$post_object = get_page_by_path( $query->query['name'], 'OBJECT', 'product' );
if( has_term( 'photographs', 'product_cat', $post_object ) ){
// modify the query here as you need, using $query->set()
}
}
}
When you’re viewing a single post of the post type ‘product’, this should allow you to modify the $query
object to change whatever you need.1
It’s important to note the snippet above is just preliminary – this might not be the fastest way to do what you want to do; it also assumes you’re using pretty permalinks.
1 Note that pre_get_posts
passes $query
by reference, so there is no need to globalise $wp_query
to make your changes – you can just make them directly using $query->set( 'query_var', 'value' );
– obviously replacing ‘query_var’ with the var you want to modify and the ‘value’ with what you want to set it to (you can use an array also).