How to uniquely identify queries?

tl;dr: build affordable unique identifiers for queries is possible, but is pretty useless. If you’re looking for unique identifiers for query objects, then you can use spl_object_hash, but IMHO is pretty useless: it is non-predictable, and also you get different id even if query vars are identical, but set on 2 different query objects. Only … Read more

pre_get_posts with tax_query causes empty result

You use tax_query incorrectly. Take a look at Codex Page tax_query should be an array which can contain: relation – it should be string (AND/OR) taxonomy term – array with defined taxonomy, field, terms, and so on. In your code your setting tax_query to: $taxquery = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ … Read more

Changing the meta_query of the main query based on custom query_vars and using pre_get_posts

Instead of trying to display all the matching events on your by-date page, you could try to display through ?post_type=event like this: function rewrite_rule_by_date() { add_rewrite_rule(‘by\-date/([0-9]{4}\-[0-9]{2}\-[0-9]{2})$’, ‘index.php?post_type=event&event_date=$matches[1]’, ‘top’); } add_action( ‘init’, ‘rewrite_rule_by_date’ ); function query_var_by_date() { add_rewrite_tag( ‘%event_date%’, ‘([0-9]{4}-[0-9]{2}-[0-9]{2})’); } add_action( ‘init’, ‘query_var_by_date’ ); function custom_event_query( $query ) { if ( get_query_var( ‘event_date’ ) && … Read more

is_category() in pre_get_posts strange error

After a bit of investigation… If you pass a category to is_category it uses get_queried_object to grab data– see the source. get_queried_object returns NULL for categories that do not exist. You can demonstrate that with: function custom_posts_per_page($query) { var_dump(get_queried_object()); } add_filter( ‘pre_get_posts’, ‘custom_posts_per_page’ ); Load a valid category archive and then an invalid one. The … Read more

Custom search filter causes menu and query_posts problems

Use is_main_query() to modify only the main query so menu will stay not affected. Try This: add_action( ‘pre_get_posts’, ‘fteh_pre_get_posts’ ); function fteh_pre_get_posts( $query ){ if( !is_admin() && $query->is_main_query() && isset( $query->query_vars[‘type’] ) ) $types = explode( ‘,’, $query->query_vars[‘type’] ); $query->set( ‘post_type’, $types ); return $query; }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)