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

WP_Query, pre_get_posts and offset

It helps to write problems down. After I haven’t used pre_get_posts extensively, I focused too much on that area for the cause, but it was the if clause. Changed to if ( ! is_admin() && $query->is_main_query() && ! is_post_type_archive( ‘cpt’ ) ) { return $query; } elseif ( ! is_admin() && $query->is_main_query() && is_post_type_archive( ‘cpt’ … Read more

How to conditionally pass a parameter to wordpress search to limit post types?

If you have a “natural” artwork archive (typically setting has_archive to true in your register_post_type() arguments), you already have the functionality in place: http://example.com/artwork/?s=query …assuming artwork is your archive slug, WordPress will search only artwork for “query”. Just set the action attribute of the search form to the archive URL, like so: <form action=”<?php echo … Read more

new WP_Query to get max price meta value not working

As @Milo suggested and also codex documented it is_main_query Under_the_Hood This function is an alias for the method WP_Query::is_main_query(). In filter or action hook callbacks that are passed the WP_Query object, such as pre_get_posts, it is circular to call this function. Instead, directly call the passed object’s method. For example, if your filter callback assigns … Read more

Using pre_get_posts for taxonomy post count

I answered my own question I just implemented it wrong when testing it on my end (mis-typed the taxonomy). This is correct: // Change the number of posts that show up on the taxonomy template function custom_tax_post_count ( $query ) { if (($query->is_tax(array(‘taxonomy_1’, ‘taxonomy_2’)) )) $query->set( ‘posts_per_page’, ‘-1’ ); } add_action( ‘pre_get_posts’, ‘custom_tax_post_count’ );