Why query_vars get altered in WP_Query Object?

Milo’s comment about pre_get_posts helped solve this issue for me. In my case the parent theme used the pre_get_posts action to explicitly set the post_type for all author pages. It wasn’t in the functions.php, but I was able to find it by searching the theme for instances of pre_get_posts. (I used grep -R “pre_get_posts” . … Read more

$wpdb->insert inserting two rows in database

Try something like this function insert_data_into_table () { global $wpdb; $table_name = $wpdb->prefix . “your_table_name”; //Check if table exists if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) : //if not, create the table $sql = “CREATE TABLE ” . $table_name . ” ( (…) ) ENGINE=InnoDB;”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); dbDelta($sql); else: foreach($emails as $mail): $insert = “INSERT … Read more

Display posts in 3 days chunk

It may be that you could use some sort of lazy loading plugin. This could be done in a custom way using admin_ajax and adding user events but there are a number of plugins available that may be able to help out. This plugin – https://wordpress.org/plugins/ajax-load-more/ – allows for the implementation of the lazy loading … Read more

Ignore post by meta value in the main query

We can try the following alternative way: Remove the two posts we select via our custom query from the main query via the pre_get_posts action Return the two posts on top of page one via the the_posts filter Lets look at possible code: add_action( ‘pre_get_posts’, function ( $q ) { remove_filter( current_filter(), __FUNCTION__ ); if … Read more

Setup of taxonomy term template pages

Added this action hook to my functions.php file: add_action( ‘pre_get_posts’, function ( $q ) { if ( !is_admin() // Only target the front end queries && $q->is_main_query() // Targets the main query only && $q->is_tax(‘course-type’) // Only target category pages ) { $q->set( ‘posts_per_page’, -1 ); } }); Then using the default loop on the … Read more