Recent activity query WordPress

This needs to be 2 queries, one to get the posts most recently commented like: $q = “SELECT wp_comments.comment_post_id, wp_posts.* FROM wp_comments LEFT JOIN wp_posts ON wp_comments.comment_post_id = wp_posts.ID ORDER by wp_comments.comment_date DESC”; And one to get the most 10 recent posts by add or edit: $q = “SELECT * FROM wp_posts WHERE post_type=”post” OR … Read more

List WordPress Post and Related Attachments outside of a post page

First of all don’t use query_posts function, use the WP_Query class instead. Secondary you forget to fetch attachments for a post. You can get attachments list by calling get_children function. $args = array ( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘audio’, ‘numberposts’ => -1, ); $the_query = new WP_Query( ‘portfolio-tags=apple&post_type=portfolio&posts_per_page=-1&orderby=title&order=asc’ ); if ( $the_query->have_posts() ) : … Read more

Disable (or limit) queries when certain content (or data) is not needed (or showed)

You can filter ‘posts_fields’, check if it is the main query and limit the queried fields to … whatever you need. See WP_Query::get_posts() in /wp-includes/query.php for details and side effects. For debugging the queries I recommend the plugin Debug Bar. If you add … define( ‘WP_DEBUG’, TRUE ); define( ‘SAVEQUERIES’, TRUE ); … to your … Read more

Conditional category query breaking?

i’m not sure what you are trying to achieve w/ the $paged variable. seems like you could simplify your query though $posts_per_page = is_paged() ? 5 : 2; $args=array( ‘post_type’=>’post’, ‘category_name’ => ‘featured-content’, ‘posts_per_page’ => $posts_per_page ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); edit, adding an offset (and fixing syntax errors): $paged … Read more

Query post & loop problem.

no idea what the problems actually are, but from looking at the code, I woud suggest: a: the while (have_posts()) : should be while ($the_query->have_posts()) : b: you would need to increment the counter: <?php $count = $count + 1; ?> c: the endif; of the loop might be missing after the endwhile; – at … Read more

get last post’s link with SQL query

Assuming each site is WP, they’ll both have RSS feeds. You’re better off just to fetch the RSS feed and get the latest post link from that. WP even has some built in support RSS parsing! <?php /** * An example of how to use fetch feed * * @uses fetch_feed * @return bool|string False … Read more

Start Query from 2nd Post without offset

With pagination is easy 🙂 -just retrieve all the posts, then skip the first one out. At the end rewind back to the beginning of the loop and output the post you missed out. if( have_posts() ): while( have_posts() ): the_post(); if( 0 == $wp_query->$current_post ) continue; // Display all but the first post endwhile; … Read more

Export all posts to import as product items

You don’t have to export and then re-import, you can do it all via the API in one go, no XML required. here’s a quick example plugin: <?php /* Plugin Name: WPA_convert_types */ function wpa_convert_types_page() { add_management_page( ‘WPA convert types’, ‘WPA convert types’, ‘manage_options’, ‘wpa_convert_types’, ‘wpa_convert_types_render_page’ ); } add_action(‘admin_menu’, ‘wpa_convert_types_page’); function wpa_convert_types_render_page() { if( isset( … Read more