Articles of offsets

Two custom loops, pagination, offset

I have two Loops using WP_Query. The first loop shows X posts. No pagination. (loop A) The second loop shows Y posts. With custom pagination. (loop B) It kinda works; but you can see the second loop repeating X posts from the first loop. First thing that comes to mind is to set an offset […]

How can I fix: “Notice: Undefined offset: 0”?

I’m Starting a WordPress website and I’m having a problem with some of my posts. This issue is only affecting 2 out of 4 articles and after investigating I cannot think on a reason for that. This error message appears right below comments section: Notice: Undefined offset: 0 in /home/***/public_html/wp-includes/class-wp-query.php on line 3152 When I […]

WP_Query: offset ignored when posts_per_page is -1?

Is it only me or this is what’s happening? I just want to get all posts starting from a certain offset, like 10. Instead I get all posts starting from the 0.

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; […]

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’ […]

Exclude first 5 posts of specific categories in the main loop

I read this article about how to set an offset for one specific category in the loop. I was wondering about if this was possible for more than just one category. My problem with the code suggested in the article linked above is that I am using a single widget to show five posts from […]

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>’ […]

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 […]

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 […]