Override main query for page template
Override main query for page template
Override main query for page template
What’s the most efficient way to get two queries based on an if statement?
There’s a couple problems I foresee here. I’m assuming the featured portion is a meta value of some sort. We can run a conditional that will run for all queries on the Front Page but it would override the meta_queries instead of append to them. The hook would look something like this: /** * Modify … Read more
why doesn’t this pre_get_posts code work?
I just found the problem, though I cannot explain why or how things went the way they did – the date to compare events by had the wrong date format: date( ‘d-m-Y’ ) should have been date( ‘Y-m-d’ ). The comparison worked until the update, so something must’ve changed about the way WordPress stores date … Read more
You need to modify the tax_query block of code like below- $q->set( ‘tax_query’, array(array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, // Here it would be ‘term_id’ instead of only ‘ID’. ‘terms’ => $allowedCats, ‘operator’ => ‘IN’ // May be it would be ‘IN’ in stead of ‘NOT IN’. Cause you are passing allowed product categories. … Read more
This might be a quick fix for your custom post type 404 error page. Navigate to Settings > Permalinks, and then click the Save Changes button. Then comeback to check if the links doesn’t give you a 404 error.
You don’t need to add a pre_get_posts filter for ?tag=xyz to work, URLs in WordPress should already work that way. If you can write it as a string and pass it to WP_Query then you can append it to a URL with a ? to add additional query parameters. That is assuming that the main … Read more
Complex query using pre_get_posts
The function you are looking for is get_current_screen(). To check if you are on a specific custom post type page, do as follows: $screen = get_current_screen(); if ( $screen->post_type == ‘custom_job’ ) { // We are on custom_job post type, good to go } Now, if you visit edit.php?post_type=custom_job, this conditional will return true, which … Read more