Pagination Not Working When Used With WP_Query() `offset` Property

I have an archive page that pulls in posts using WP_Query(). On the homepage of the site it shows 16 of the custom post type posts, so on the archive I offset the archive page by 16 posts. The code for this is: $newsArticles = new WP_Query(array( 'posts_per_page' => 16, 'offset' => 16, 'post_type'=> 'news' )); while( $newsArticles->have_posts()){ $newsArticles->the_post(); ?> // HTML <?php } ?> However on this archive page the <?php echo paginate_links();?> function to show the pagination pages …
Category: Web

Style first 3 posts differently and use a 2nd loop to get rest of posts / offset and pagination broken

I'm working on a theme and I am having trouble with loops/pagination breaks when using an offest. I looked online and tried to use only 1 loop (per this post) but I'm having trouble making it work. I want to have the first 3 posts at the top of the page be the most recent (post 1-3), and then bottom 3 posts to be the next 3 (post 4-6), when you click on the pagination I want it to be …
Category: Web

Manipulated offset and pagination, can't display last post anymore

As you can see from the code below, i'd like to show the last post with a design and the other posts with a different design on the first page. For the rest of the archive pages the last post won't be showed. I manipulated the pagination and offest reading this article : https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination But this is affecting my first loop showing directly the 2° post and ignoring the offset i declared Any solutions for making the last post work …
Category: Web

Undefined offset: 0 in WordPress after latest version upgrade

My WordPress powered website always worked great, however after the latest upgrade to 5.6.2 and 5.7 I have a major issue that actually breaks an important part of the website, I have seen to go through the logs and found the following error: [14-Mar-2021 00:29:32 UTC] PHP Notice: Undefined offset: 0 in /var/www/html/wp-content/plugins/tours/includes/class-tours-tour-post-type.php on line 1709 [14-Mar-2021 00:29:32 UTC] selected_original_tours: The code in question seems to be the following: if($show_filter) { $selected_destinations = isset($_GET['destinations']) ? explode(',', $_GET['destinations']) : []; $selected_tourstyles …
Category: Web

Missing image in gallery shortcode in custom feed

I have problem with custom gallery shortcode and missing first image in each gallery block. For example: [gallery ids="1,2,3,4,5"] show only 2,3,4,5 pictures. This custom shortcode is part of wordpress plugin which make custom feed. It works correctly on my second site with same plugins and theme (tested on localhost). I've tried to update whole wordpress installation, disabled all plugins with no success. So the problem is somewhere in db or with server? I'm do not have any idea how …
Category: Web

Querying Different Categories in Different Loop With Different Offsets

I have four loops. In the first loop I want to display all current articles from all categories (breaking news). In the 2nd loop only articles with the category 4,5,6,7 should be displayed. But if in the 1st loop an article from these categories were published, this newest article should not appear in the 2nd loop. I would be very grateful about helpful tips and code snippets.
Category: Web

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 search for that line, I find this function: I have search for this function in my WordPress code and I only found a few matches: …
Category: Web

setting offset to category number in archive page

unit test data added many category to some posts.so, on archive page, the long category list seems bad because you know its long, ugly. so, to solve this visual problem, I want to set offset to this category number. How can I do it? here is my archive page.I tried to add offset to the wp query but it doesnt work. you can check the archive page with this link: https://unit-test-data.deniz-tasarim.site/category/edge-case-2/ ( Edge Case: Many Categories ) archive.php: <?php get_header(); …
Category: Web

Apply query arguments after the nth post

I can't seem to find an answer/solution to this. If there is one out there, please post a link. My understanding is that in a wp_query, offset refers to the results of the query. So if I set 'offset' => 4, it will ignore the first 4 posts that match the arguments. What I'm interested in is ignoring the most recent - let's say - 4 posts and only run the query and check for posts that match the arguments …
Category: Web

WP_Query offset argument does not work

I want to display all posts starting from a certain offset, my query is: WP_Query( array( 'posts_per_page' => -1, 'offset' => 20, 'cat' => 5, ) ); This query shows all posts without starting from the offset value. Whys is that?
Category: Web

WP Query with offset breaks wp_pagenavi or any pagination

I am working on a custom loop using WP_Query using the offset parameter. The problem is that as soon as I add the offset, it breaks the pagination, displaying the same links no matter the page number. <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query_args = array( 'post_type' => 'notice', 'posts_per_page' => 6, 'offset' => 1, 'paged' => $paged ); $the_query = new WP_Query( $query_args ); ?> <?php if ( $the_query->have_posts() ) : ?> <?php while ( …
Category: Web

WP_Query arguments order

Given the following example of a custom query $query = new WP_Query(array( 'posts_per_page' => 7, 'categor_name' => 'events', 'offset' => 5 )); Does the order of arguments matter? Will this query first select all posts with the given category and then offset the first 5 or will it first offset all 5 posts then select posts with given category?
Category: Web

How to use offset in WP_Query

Where do I put the offset function? <?php $args = array( 'post_type' => 'post', 'category_name' => 'category', 'orderby' => 'date', 'order' => 'DESC', 'showposts' => 4); $wp_query = new WP_Query($args); if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
Category: Web

Blog page pagination is not working after using the offset argument

I have displayed the recent 7 posts then shown the remaining posts. So I have added the offset = 7 in the argument to skip above 7 recent posts and display remaining posts but the pagination not working. Pagination URL changes like xxx.com/page/2, xxx.com/page/3, etc but the posts do not change. I was a wonder if anyone can help me. Here is my code. Index.php get_header(); ?> <div class="container"> <?php if (is_home() && !is_front_page()) : ?> <header class="page-header"> <h1 class="page-title"><?php …
Category: Web

AJAX Breaking Offset Argument In WP Query

I have been using AJAX on my website successfully and for my category.php page I need to use the offset argument. Unfortunately, AJAX creates complications with offset and I get the same posts looping over and over. I consulted the WordPress codex but I couldn't not figure out how to apply a solution to my particular WP_Query. Anyone that can help I'd be grateful, I can provide more code if necessary as well. Thanks! category.php <?php $category = get_category( get_query_var( …
Category: Web

Timezone for Plugin

I'm using these two lines: $expires = strtotime( $_POST['expire_date']); if($expires < time()) to test the time in the name=expire_date form against GMT time. But no matter what I do my expire date time is 5 hours off. I'm in GMT -5, so I'm trying to adjust the top line: $expires = strtotime( $_POST['expire_date']) - (( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )); But it's not working. Any ideas for correct GMT offset handling in Wordpress?
Category: Web

Undefined index when saved to options

$options = get_option('analytics'); if ( ! preg_match( '/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $options['analytics_startdate'] ) ) { $options['analytics_startdate'] = '2018-12-01'; } Why this is throwing an error : Undefined index: analytics_startdate , though i am specifying it.
Category: Web

Page navigation doesn't seem to work when I add offset?

I am trying to get a simple navigation to work, it works when I don't use offset in the arguments. but I like to do something special with the first post $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => '6', 'cat' => 5, 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged );` So for these I add $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'offset' => 1, //<--- …
Category: Web

Best practice and technology to Offset anchor links

I am using anchor links in the Front Page of this Website. They are in ACCUEIL, SPORTIVES, VOYAGES and CONTACT. In order for the anchor links to land in the right place, below the menu upper bar, is to use a 50px division. Nevertheless, the spaces between the title and the upper element are uneven; for example, the space over ACCUEIL is greater the space over SPORTIVES. If you navigate through the anchors, you will see the difference. ¿Any JavaScript …
Category: Web

Offset Page Loops and Pagination

I have really been struggling with getting the main loop for the index.php to work properly with WP_Query functions. I need the grid array of 6 featured images at the top to not be offset at all, while offsetting the main posts loop below it by 6 posts. Anything involving query_posts() inevitably ends up breaking the pagination. Using a single loop fixes the pagination issue, but undesirably applies the offset to the featured grid section. I have managed to get …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.