Exclude post from wp_query based on custom field boolean

Excluding things in queries is extremely expensive, but also avoidable. What’s more, filtering posts by their post meta values is also super expensive. That query would get exponentially slower as the post count rises. Instead you can avoid this completely by telling it what you do want, not what you don’t want. So instead of … Read more

pre_user_query vs pre_get_posts

The pre_get_posts function is a simple query modifier for general “post” queries. If you’re looking to modify the SQL directly for these query I suggest using the post_clauses hook. This hook passes an array of SQL clauses such as: $sql[‘where’] and sql[‘join’] Here you can inject your own custom SQL into the specific clauses. That … Read more

Pagination Not Working When Used With WP_Query() `offset` Property

WP_Query docs gives a warning about the offset parameter: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination. Try something like this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $newsArticles = new WP_Query(array( ‘posts_per_page’ => 16, ‘post_type’=> ‘news’, ‘paged’ => $paged, )); while( $newsArticles->have_posts()){ $newsArticles->the_post(); ?> // HTML <?php } ?> $big = … Read more

Function is printing twice – any suggestions?

After realizing that I was trying to use the same shortcode for two different types of lists, it was easier to just separate them in two different shortcodes. To list all posts and break them up by type: /** * Shortcode for listing all tools matching tags * Usage: [useful-tools-all desc=”true” li=”true” tags=”health, teens”] * … Read more