According to https://www.ads-software.com/support/topic/front-page-query_posts-limit-posts-only-on-first-page-1
I found that 5 posts from offset are not displayed on last page – they needs next page.
I have 408 published posts.
So $wp_query->max_num_pages = 41
.
But index.php is:
global $query_string;
$front_limit = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ( is_paged() ? ( ($paged - 2) * $posts_per_page + $front_limit ) : 0 );
$posts_per_page = get_option('posts_per_page');
$my_query = '&ignore_sticky_posts=1';
$my_query .= '&offset='.$offset;
$my_query .= '&paged='.$paged;
if ( !is_paged() ) :
$my_query .= '&posts_per_page='.$front_limit;
else :
$my_query .= '&posts_per_page='.$posts_per_page;
endif;
query_posts( $query_string . $my_query );
So on 41 pages I have 405 posts (41 pages limited to 410 posts, but front page takes only 5 posts and following pages have offset by those 5 taken from front page).
And 3 last posts are missing.
Correctly number of pages should be:
$front_limit = 5;
$total_posts = $wp_query->found_posts;
$posts_per_page = get_option('posts_per_page');
$total_pages = ceil( ( $total_posts - $front_limit ) / $posts_per_page ) + 1;
I have no problem to modify navigation to set max number of pages 42, but page 42 just no exists.
Temporarily I just used trick for last page (41):
if ( !is_paged() ) :
$my_query .= '&posts_per_page='.$front_limit;
else :
if ( $paged == $wp_query->max_num_pages ) $posts_per_page += $front_limit;
$my_query .= '&posts_per_page='.$posts_per_page;
endif;
So page 41 displays up to 15 posts (in my case 13).
But this is not satisfactory result. If someone have an idea, please let me know.
Note: fix for first page posts navigation is
$args = array_merge( $wp_query->query_vars, array( 'showposts' => get_option('posts_per_page')) );
query_posts( $args );
before call of "paginate_links"
Thanks in advance!
Greetings
When using the “tax_query” parameter in my arguments, I am not getting all the posts returned – but despite this “found_posts” is returning the correct amount. This ONLY happens when using the “tax_query” parameter, the “s” parameter alone works perfectly.
Here are the arguments I am passing https://pastebin.com/0Ak98EHe
Any help with this would be greatly appreciated,
Thanks,
WazzaJB
I am using WP_Query and have found examples showing how to filter to stickies, and how to filter to only posts that have thumbnails. The sticky filter works, but the thumbnail post doesn’t work properly.
Currently, I have 5 sticky posts, but only 2 have thumbnails, so I am expecting 2 posts to be displayed. $found_posts correctly says that there are 2 posts that match, however, post_count is 5 and all 5 are showing up in the loop.
The code I am using is here in this pastebin: https://pastebin.com/aJz2cyhA.
I have tried a number of different variations, including specifying greater than 0 or not empty for the _thumbnail_id. I’ve also tried using meta_key rather than a meta_query and turning on and off paging, but nothing seems to make any difference.
(I do know I can work around this by checking has_thumbnail before I output the slider content for that post, but I really want to know what I am doing wrong with this query, in case I make the same mistake in other places.)
Any suggestions appreciated!
]]>I’m just getting started in WP experience and I meet a little problem : I’m using this Wp_Query :
$agenda = new WP_Query( array(
'cat' => getCurrentCatID(),
'meta_key' => 'date',
'meta_value' => getDateWithTol(),
'meta_compare' => '<',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => get_option('posts_per_page'),
'paged' => (get_query_var('paged')) ?
get_query_var('paged') : 1 ));
This query return 4 posts, but the property $wp_query->found_posts returns 32 posts which creates problem with the plugin wp_paginate which creates more pages than it is needed…
Is anybody has an idea or can hep me please ?
Thanks a lot !
I’m needing to show the total amount of post resulting from a query, I see always in the forum is structured as follows: “$wp_query->found_posts”
However, the theme I’m using uses the structure to make the queries as follows:
$args=array(
'showposts' => 10,
'paged' => $paged,
'year' => $today["year"],
'monthnum' => $today["mon"],
'day' => $today["mday"],
'meta_key' => $meta_key,
'orderby'=> 'meta_value_num',
'order' => 'DESC'
);
query_posts($args);
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
How do I get the value of $found_posts query with this structure?
]]>echo $wp_query->found_posts;
Is there any other way to find the total number of post returned by a query i am using wp_query($args)
Thanks in advance
]]>On our site we want to add the possiblity for the user to choose the content (s)he would like to read about the most. Therefore, I added a simple form which displays all terms of our custom taxonomy (which is assigned to a custom content type).
Once the user made his/her choice, the term ids are saved in a COOKIE.
What I need now is a hook to change *all* queries to reflect the user’s preference.
Example:
I have a custom content type called “News”. This content-type has a custom taxonomy called “Flowers”. The taxonomy has different terms (e.g. colours) like: Green, Blue, etc. On the front page the user chose to only see News (the content type) that have the term “Green” assigned to the taxonomy “flowers”. This is now the global setting. Whenever a list of news is being displayed it filters out all entries that do not meet the requirements.
Is this even possible like that?
I tried finding some useful info on the “Custom Queries”-Codex page and also checked the pre_get_posts / found_posts hooks/filters to no avail.
pre_get_posts sounds perfect, but can it work with custom taxonomies?
Any help is much appreciated. Thanks!
]]>Apart from that, all other features work fine on both sites.
For testing, I created an archive.php file, with no extra plugins or functions, with a single line of code giving different results on 2 sites:
<?php echo $wp_query->found_posts; ?>
I would greatly appreciate any help, as I am completely baffled.
]]>On my local windows apache server, the blog pages and the archives are not showing the next/prev posts, not matter how many posts I specify in the settings or how many posts I have.
I have re downloaded and installed wp 3.0 manually. Deactivated all plugins, reinstalled twentyten 1.0 in case it was that, but it appears to be theme independent and still happens when no plugins – this is happening to all themes.
I managed to track it down in includes>query.php to
‘found_posts’ being 0 (although posts are displaying and not_found is false)
which makes max_num_pages = 0, which means the “links” get skipped when loop.php checks it.
This is not happening on my remote servers (also on 3.0 and 2010 theme).
I have googled and tried checking the trac, but did not see anything that may explain or relate.
I have to leave this a bit and somehow test my new plugin without this, but it is concerning. I had some weird query post behavior too where ‘post_per_page’ = -1 did not appear to work and was wondering if it is related?
Anyone shed any light?
]]>I have a blog with 244 post in it within the only category (id=1)
i am trying to set up a pagination plugin (wp-page-numbers) and met following issue
with 24 posts per page I got only 9 pages in my navi 1 2 … 9
but I should have 244/24 = 10.1 – at least 11 pages
after some investigations I found out that ->found_posts returs only 216 – thus 28 posts were invisible for found_posts property..
after that a went through my posts and got following distribution:
March = 120 posts
Feb = 96 posts
Jan = 28 posts
so it looks like by default found_posts “sees” only posts from Mar and Feb, but cannot see early posts..
anybody could help me with idea where should I dig in?
]]>