Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Created April 25, 2013 14:28
Show Gist options
  • Save paulgibbs/d51754a02ad3e31213a5 to your computer and use it in GitHub Desktop.
Save paulgibbs/d51754a02ad3e31213a5 to your computer and use it in GitHub Desktop.
{
"name": "vip_get_random_posts",
"line": 571,
"arguments": [
{
"name": "$amount",
"default": "1",
"type": ""
},
{
"name": "$return_ids",
"default": "false",
"type": ""
}
],
"doc": {
"description": "Get random posts; an alternate approach for dealing with large tables.",
"long_description": "<p>MySQL queries that use ORDER BY RAND() can be pretty challenging and slow on large datasets.\nThis function is an alternative method for getting random posts, though it's still very very inefficent.\nYou probably don't want to use this function.<\/p>\n\n<p>Override the $vip_get_random_post_ids_where_add global to add your own WHERE condition:\n$vip_get_random_post_ids_where_add = \"AND post_status='publish' AND post_type='post' AND post_date_gmt > '2009-01-01 00:00:00';<\/p>\n\n<p>You'll want to enable caching and avoid querying all posts by adding the following action:\nadd_action( 'save_post', 'vip_refresh_random_posts_all_ids', 1 ); \/\/ add this to functions.php<\/p>",
"tags": [
{
"name": "author",
"content": "tottdev"
},
{
"name": "param",
"content": "int $amount Optional. Amount of random posts to get. Default 1."
},
{
"name": "param",
"content": "bool $return_ids Optional. To just get the IDs, set this to true, otherwise post objects are returned (the default)."
},
{
"name": "return",
"content": "array"
}
]
},
"hooks": [
{
"name": "'vip_get_random_posts_random_posts'",
"line": 609,
"type": "filter",
"arguments": "$random_posts"
}
]
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment