Offset Page Loops and Pagination

I messed around with the code some more, and my particular issue actually ended up relating to the original if statement parameters. Changing the condition to check the home page for queries to if ( $query->is_home() && ! $query->is_main_query() ) { return; } and else { //This is the first page. Just use the offset… … Read more

Change searched term

The pre_get_posts filter is the right place to go. You can check if you are on a search query, and alter it the way you want. Here’s an example: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { // Check if we are on a search page if ($query->is_search) { // Get the search … Read more

Search function works improperly

This code should work OK, but… There are some problems with it. Let’s break it apart and add some comments. function searchcategory($query) { if ($query->is_search) { // Checking only for is_search is very risky. It will be set to true // whenever param “s” is set. So your function will modify any wp_query with s, … Read more

Custom post type show on both Home and Date Archive

In your code ( $query->is_home() && $query->is_date() && $query->is_main_query() ) always returns false because $query->is_home() and $query->is_date() cannot be true on same page. Try this, function add_custom_post_type_to_query( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_date() || $query->is_home() ) { $query->set( ‘post_type’, array(‘post’, ‘pictures’) ); } } } add_action( ‘pre_get_posts’, … Read more

Formulate a url to show posts with both taxonomy terms

Looks like you can define the AND logical operator with the URL parameters, specifically adding the “+” between your terms like this: url?taxonomy=term1+term2 This will ensure that only posts containing all terms listed are returned. Example: https://example.com/blog?food=sauce+cheese [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => food [terms] => … Read more

Using pre_get_posts to filter one loop in a multiloop archive

Add the filter where you need it and remove it afterwards. add_action(‘pre_get_posts’,’blog_filter’); // your query; presumably WP_Query // your first loop remove_action(‘pre_get_posts’,’blog_filter’); // another query; presumably WP_Query // your second loop You can also make your action self-removing: function blog_filter($query) { remove_action(‘pre_get_posts’,’blog_filter’); if ( !is_admin() && $query->is_main_query() ) { if ($query->is_post_type_archive(‘rg_blog’)) { $query->set(‘post_type’, ‘post’); } … Read more

Issue with pre_get_posts on custom post type archive pages

If we look in source, we’ll see under what conditions is_archive is true: if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) $this->is_archive = true; The issue is that is_archive is triggering your filter on your post type archive. If you want to exclude those, either make sure it’s not … Read more

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