Query random post from different categories

Random ordering is quite expensive operations in SQL and can become a headache on very big sites. Getting a random post from a category for 6 categories will mean you might need to run 6 separate queries, each ordered randomly. This can really break the bank and leave you bankrupt. From your answer and looking … Read more

WordPress ajax get content post id

There are many errors and bad practices in your code. I’ve fixed most of them. Explaining all those here is not possible. I’ve written the explanation as comment where they need to. Please read the whole code and comments attentively- custom.js // Wrap any jQuery code like this. It makes ‘$’ use fullproof // and … Read more

How do you Query posts with nothing in common?

Maybe you’re looking for the post__in parameter in WP_Query. $query = new WP_Query(array( ‘post__in’ => array(23,18,2,199,6,8) ); And then: while ( $query->have_posts() ) { $query->the_post(); /* post loop */ } Take a look at the docs. =D For public queries: post__in is not public queryable by default, so you can just validate and copy $_GET[‘post__in’] … Read more

how to get specific page content

Rather than call WP_Query() you can use get_post() and “set up” the global $post. This is probably a little more efficient than @tf’s answer, though the ideas are broadly the same. Please note, in both cases you should reset the post data afterwards. /** * Display the post content. Optionally allows post ID to be … Read more

Get latest posts from multiple categories

2 choices here, you either need to set the category as an array e.g. $args = array( ‘posts_per_page’ => 5, ‘category’ => array(15,16,17,18,19) ); You can’t just add the numbers in a list but I can’t find any documentation that the category element allows multiples (as the name is category) The other option is to … Read more

Adding Pagination on a Custom Author Page

Put the following code in your functions.php file. function limit_posts_per_page() { if ( is_author() ) // you can limit other pages as well ( i.e. is_archive() ), if need be. return 5; } add_filter( ‘pre_option_posts_per_page’, ‘limit_posts_per_page’ ); Make sure your using the author.php template, otherwise it wont work. Please have a look at twentyten’s author.php … Read more