Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 736

A generic term referring to the process of retrieving information from a database.

8 votes
3 answers
2k views

Remove the Homepage Query

The main query still pulls in the standard 10 posts, but since I'm not displaying these, I'd like to eliminate the query being made to the database entirely. … I could use pre_get_posts to minimise and reduce the query, but that still leaves me with a very fast query, how do I eliminate it entirely? …
Tom J Nowell's user avatar
  • 60.6k
6 votes

Filter the query ONLY for the search results page

Functions such as is_page_template etc rely on the main query, but we're in a pre_get_posts filter, you don't know if that query has been set yet, or if you're filtering that query or another. … WordPress decides which template is loaded based on the main query. If it's the main query, and is_search is true, then search.php will be loaded. …
Tom J Nowell's user avatar
  • 60.6k
5 votes

Is it good practice to use wpdb->query() function?

Is it a good practice to use wpdb->query() function each time by passing my query to the function instead of using the dedicated functions like insert() and delete() etc? … It takes a table creation query as a parameter, and it has to be formatted in a particular way or it won't work. wpdb->query is inappropriate for creating tables. …
Tom J Nowell's user avatar
  • 60.6k
4 votes

Wp get all the sub pages of the parent using wp query

The Problem What you're having problems grasping is "How do I do X?" This isn't a 1 step action, it's a multistep process, and it needs to be broken apart. You don't need to do this: get all the po …
Tom J Nowell's user avatar
  • 60.6k
3 votes
Accepted

Query only the posts with a post format of "audio"

I saw in your original code you completely discard the original main query ( yet another reason query_posts is terrible ). … So if this is your home page, you could do this: function audio_only( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'post_format', 'post-format-audio' ); …
Tom J Nowell's user avatar
  • 60.6k
3 votes

Pass array of taxonomy terms to wp_query

> array( 'quotes' ), ), array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-quote' ), ), ), ); $query
Tom J Nowell's user avatar
  • 60.6k
3 votes
Accepted

Create ONE callback for all page templates, post filter queries + paginated pages, triggerin...

Even if there was a main query it would not be the same main query. … get_query_var won't work, there is no main query to get a query var from! ). …
Tom J Nowell's user avatar
  • 60.6k
3 votes
Accepted

What is the best way to cache pages and queries in WordPress?

No, there isn't. WordPress does not provide page caching mechanisms, and has no APIs for it. There is no generic way to say example.com/page is now stale and needs recreating. Nor is there any generic …
Tom J Nowell's user avatar
  • 60.6k
3 votes

Improving WP_Query for performance when random posts are ordered

This is bad as it discards the main query and launches a second query. The cost of the first query still occurs, but it's discarded so it's a waste of time. … Consider using pre_get_posts instead to intercept the main query and change it …
Tom J Nowell's user avatar
  • 60.6k
3 votes

How to speed up wp_query, took more 5s to run against 100k posts

Moving to a custom taxonomy will improve your query speed by orders of magnitude. … a post, and you don't need to filter/query for that data, use post meta And don't be afraid to use both or approximations if you have a more complicated value such as a price …
Tom J Nowell's user avatar
  • 60.6k
3 votes
Accepted

Check if an option exists and get its value in one hit

I'm hitting the table 2 times (if the field exists) to get its value. No, you aren't, and there is no evidence for this. You may not be hitting the database at all if it has autoload enabled. WordPr …
Tom J Nowell's user avatar
  • 60.6k
2 votes

How to display posts under a specific subcategory of a given category

If you pass anything using this GET variable, Wordpress will modify the query accordingly assuming its a category. This is bad news. …
Tom J Nowell's user avatar
  • 60.6k
2 votes
Accepted

Get the most popular terms for a custom post type

That way when you want to do your list, you query the second hidden taxonomy, which acts as a cache of sorts. …
Tom J Nowell's user avatar
  • 60.6k
2 votes

How to get one result using wpdb class?

You've made no attempt to check for errors, e.g. $result may be false, also your code would fail if there was more than one result returned. So instead of using a custom table, and reinventing the wh …
Tom J Nowell's user avatar
  • 60.6k
2 votes

Remove the Homepage Query

For reference, before: 45q, after: 42q The code is very similar to the code used by @birgire function _tomjn_home_cancel_query( $query, \WP_Query $q ) { if ( !$q->is_admin() && ! … $q->is_feed() && $q->is_home() && $q->is_main_query() ) { $query = false; $q->set( 'fields', 'ids' ); } return $query; } add_filter( 'posts_request', '_tomjn_home_cancel_query', …
Tom J Nowell's user avatar
  • 60.6k

15 30 50 per page