Ordering by meta_key

That happens because of the way WordPress structures the MySQL queries, and the way posts joins postmeta. If a post doesn’t have a value in featured, it won’t join. Here are two options for you: Update the way you’re storing featured to store the value regardless (either ‘1’ or ‘0’). Ensure that every post has …

Read more

Remove category from query (show all posts in archive.php) pre_get_posts()

Just unsetting the cat variable probably isn’t enough. The pre_get_posts hook happens after the query variables have already been parsed. So there’s probably a tax_query with the taxonomy = category and the terms = your category. You’re already dumping the $query in your code, presumably for debugging. So, look at what you’re actually dumping. Do …

Read more

Injecting a custom sql query into a page/theme

The hooks you are looking for can be found in the WordPress Codex WP_Query – Filters: Filters posts_distinct – Alters SQL ‘DISTINCTROW’ clause to the query that returns the post array. posts_groupby – Alters SQL ‘GROUP BY’ clause of the query that returns the post array. posts_join – Alters SQL ‘JOIN’ clause of the query …

Read more