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’ );

pre_get_posts query between 2 dates (date stored in custom post meta)

You can always use a BETWEEN comparison in your query, I have used this, maybe you can adapt it to work in your situation. It avoids doing multiple checks for no reason 🙂 $first_date = 110501; $second_date = 170514; $meta_query = array( ‘key’ => ‘_exm_date’, ‘value’ => array($first_date, $second_date ), ‘type’ => ‘DATE’, ‘compare’ => … Read more

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