Show two random posts from custom post type

You need an orderby argument. $args = array( ‘post_type’ => ‘custom_advert’, ‘posts_per_page’ => 2, ‘orderby’ => ‘rand’ ); That should pull posts in a random order and stop after retrieving the first two, hence two random posts.

Get attachment by slug

An attachment is just a post with the post_status = inherit and the post_type = attachment, so can be queried with WP_Query or get_posts. Note that slug (post_name) is unique per post type. $_header = get_posts(‘post_type=attachment&name=book-site-header&posts_per_page=1&post_status=inherit’); $header = $_header ? array_pop($_header) : null; $header_url = $header ? wp_get_attachment_url($header->ID) : ”; you can also use the … Read more

Query to return maximum of one post per author

You need to GROUP BY the author ID, which is going to require a filter on posts_groupby. The Codex page for that filter is non-existent but it works like posts_join. Something like… function filter_authors($groupby) { global $wpdb; $groupby = ” {$wpdb->posts}.post_author”; return $groupby; } add_filter(‘posts_groupby’,’filter_authors’); $args = array( ‘showposts’ => 3, ‘author’ => “1,2,3” ); … Read more

Make First post different from rest?

You could check current_post in the loop: if($queryObject->have_posts()) { while($queryObject->have_posts()) { $queryObject->the_post(); if( 0 == $queryObject->current_post ) { // this is the first post } else { // not the first post } } }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)