Most commented / popular posts and offset

I am using this code to show 3 most popular posts based on number of comments : <?php $pop_posts = 3; $popularposts = “SELECT $wpdb->posts.ID, $wpdb->posts.post_title, COUNT($wpdb->comments.comment_post_ID) AS ‘stammy’ FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = ‘1’ AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=”publish” AND comment_status=”open” GROUP BY $wpdb->comments.comment_post_ID ORDER BY stammy DESC LIMIT “.$pop_posts; $posts = $wpdb->get_results($popularposts); if($posts){ … Read more

Custom query, works, but I get a “Notice: Undefined offset: 0…”

My custom query works, but in debugging mode I get this error: Notice: Undefined offset: 0 in /storage/content/24/150624/mydomain.com/public_html/wp/mysite/wp-includes/query.php on line 2232 This is what my query looks like: <?php $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); ?> <?php global $post; $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘machinecategory’, ‘terms’ … Read more

Using Offset in Custom Post Type Query

I’m using the following query for a custom post type: <?php $posts = get_posts(array( ‘numberposts’ => -1, ‘offset’ => 20, ‘post_type’ => ‘faqs’ )); if($posts) { foreach($posts as $post) { echo ‘<li class=”faq”> <p class=”title”><a href=”‘ . get_permalink($post->ID) . ‘”>’ . get_the_title($post->ID) . ‘</a></p></li>’; /*<h4 class=”title”><a href=”‘ . get_permalink($post->ID) . ‘”>’ . get_the_title($post->ID) . ‘</a></h4><p>’ … Read more

Different ‘posts_per_page’ setting for first, and rest of the paginated pages?

How do you set the posts_per_page query setting so that a different number of posts are displayed on the first of the paginated pages (of home, archive, search, etc.) and the rest of them? For example, say I’d like to display 10 posts on the first of the paginated pages of category archives, and 15 … Read more

How can I create a category landing page followed by pages of posts?

I’m trying to create a category template in my theme that will display static content if the user is on the first page of the archive, and then display the posts in the category on the following pages. I’m basically trying to replicate the category behavior on Wired.com where http://www.wired.com/category/design is a landing page while … Read more