Remove category from query (show all posts in archive.php) pre_get_posts()

Just unsetting the cat variable probably isn’t enough. The pre_get_posts hook happens after the query variables have already been parsed. So there’s probably a tax_query with the taxonomy = category and the terms = your category. You’re already dumping the $query in your code, presumably for debugging. So, look at what you’re actually dumping. Do … Read more

Injecting a custom sql query into a page/theme

The hooks you are looking for can be found in the WordPress Codex WP_Query – Filters: Filters posts_distinct – Alters SQL ‘DISTINCTROW’ clause to the query that returns the post array. posts_groupby – Alters SQL ‘GROUP BY’ clause of the query that returns the post array. posts_join – Alters SQL ‘JOIN’ clause of the query … Read more

Exclude post by custom meta with pre_get_posts

Your can use the “meta_query” argument of the query, I think is better than filter the post_where: add_action( ‘pre_get_posts’, ‘bbwp_calendar_visible_events’ ); function bbwp_calendar_visible_events( $query ) { $postType=”bbwp_calendar”; if ( !is_admin() && $query->is_main_query() ){ if ( is_post_type_archive( $postType ) ) { $meta_query = array( ‘relation’ => ‘OR’, //current time <= event_end_date array( ‘key’ => ‘event_end_date’, //Check … Read more

Can I set my WP_Query to be a Main Query?

This is an overly complicated approach. pre_get_posts will work for any query and there are numerous ways to control when/how the callback behaves: Add and remove the callback: function dummy_action($q) { } add_action(‘pre_get_posts’,’dummy_action’); $q = new WP_Query( array( ‘post_type’ => ‘post’ ) ); remove_action(‘pre_get_posts’,’dummy_action’); Use a self-removing callback: function dummy_action($q) { remove_action(‘pre_get_posts’,’dummy_action’); } add_action(‘pre_get_posts’,’dummy_action’); $q … Read more

How to achieve post_status__not_in?

Unfortunately there is no post_status__not_in query argument, but you can simply query for all statuses other than trash & draft: $stati = array_keys( get_post_stati() ); unset( $stati[‘trash’], $stati[‘draft’] ); $stati = array_flip( $stati ); $query->set( ‘post_status’, $stati );

Complex WP SQL Query

After hours of searching and testing I finally came to a solution. This code and SQL shows events with a parent id of 0 and is ordered by the dates of child events. Raw SQL cannot be used to replace the default way WP queries the database but there are always some kind of workaround … Read more

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