Get a user’s most recent post title

You just set the ‘author’ parameter in a WP_Query query or get_posts (which accepts the same parameters): $recent = get_posts(array( ‘author’=>1, ‘orderby’=>’date’, ‘order’=>’desc’, ‘numberposts’=>1 )); if( $recent ){ $title = get_the_title($recent[0]->ID); }else{ //No published posts } (Note the ‘orderby’ and ‘order’ here are redundant because they are set to their default values, but you get … Read more

Transient not working for custom loops

I have actually worked on a post yesterday (check it out here) and was hit by the same problem. I’m also new to the Transient API, never actually worked with it :-). The problem here is that for a specific loop you need to use a certain value outside of your transient. You are simply … Read more

Query multiple taxonomy in Custom Post Type

There’s the “tax_query” argument available since the latest wp release: global $query_string; $args[‘tax_query’] = array( array( ‘taxonomy’ => ‘status’ ,’terms’ => array( ‘available’, ‘pending’ ) // change to “sold” for 2nd query ,’field’ => ‘slug’ ), ); $args[‘post_type’] = ‘listing’; parse_str( $query_string, $args ); $avail_n_pend = query_posts( $args ); if ( $avail_n_pend->have_posts() ) : while … Read more

Run again current query via ajax but changing a var

You have to note that an ajax request is an entirely new http request, so the $query variable is defined in the page that send the ajax request but will be not set in the page that receive the request. That means that you have completely recreate the query and not change a param. That … Read more

Delete post revisions on post publish

I think a small plugin with the hook ‘publish_posts’ is enough. But I dont know about a core function to delete revisions and I use a query with WP functions. The source is untested, written only for this post. <?php /** * Plugin Name: WPSE71248 Delete Revisions on Publish Posts * Plugin URI: http://wordpress.stackexchange.com/questions/71248/ * … Read more

Limit number of pages in pagination

Before I start, do not use get_posts for paginated queries. get_posts legally breaks pagination, and does not return the query object. If you need to paginate queries, use WP_Query As for your issue, I really don’t think limiting the total overall amount of posts to only 100 is possible when you involve pagination. The only … Read more

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