How to query most recent post for each author?

You can write a SQL query to achieve this: <?php $sql = <<<SQL SELECT p.ID, p.post_title, p.post_author FROM {$GLOBALS[‘wpdb’]->posts} p INNER JOIN ( SELECT ID, post_title FROM {$GLOBALS[‘wpdb’]->posts} ORDER BY post_date DESC ) s ON p.ID=s.ID WHERE p.post_type=”post” AND p.post_status=”publish” GROUP BY p.post_author SQL; $rows = $GLOBALS[‘wpdb’]->get_results( $sql );

trying to change from query_post to WP_Query

The problem here is caused by variable scope… Everything is fine, when you use global $wp_query, because it is a global variable and functions like have_posts and the_post are aware of that, so you can use them in template parts. On the other hand, you define your custom query. Then you get template part and … Read more

Query Post interferes with Pagination

query_posts() is going to alter the main query, and it doesn’t sound like you want that. I would recommended using the WP_Query object to get the other posts. That said, if you must use query_posts(), call wp_reset_query() at the end of your foreach to reset your main query back to the original one.

Order Posts in Custom Order

With register_post_type(), you can specify the ‘page-attributes’ => true property, and you’ll get the “menu order” metabox which you see on pages. With this you can custom order your items, where the default is always 0, which means they will always show, even if you don’t set a value. You don’t actually have to set … Read more

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