When I click a pagination link in my custom post type "works" listing of posts (or enter a URL like "mysite.com/works/page/2"
, I get the 404 page.
Regular post type pagination (blog) works correctly. Plus, everything else regarding my custom post type "works" seems to work fine.
My
file has this:
<pre class="lang-php prettyprint-override">
The same code (replacing the post-type, of course) is used in the
, where pagination links work correctly.
And then in
I've got:
<pre class="lang-php prettyprint-override">
For a moment I thought that was happening because WordPress couldn't find any post within the loop: it tried to get the post ID when there were no post, as in line 29 of
. But then I realized this:
If I type, for example, the URL "(...)/blog/page/456", the blog template loads with the message "Nothing here". No 404 error page.
On the other hand, the URL "works/page/2", which I expect to return some posts, ends on a 404 error page.
Why?
<strong>EDIT:</strong>
On the 404 page I also get this error:
<blockquote>
Trying to get property of non-object in
(…)/wordpress/wp-includes/post-template.php on the line 29.
</blockquote>
...but it might not be related to the pagination problem. I managed to remove the code which causes this error (from a plug-in I customized) and the pagination still doesn't work.
<strong>EDIT:</strong>
This is what I got by debugging the URL <em>mysite.com/trabalhos/pagina/2</em> with the Debug-this plug-in. It seems to be very wrong:
<em>Obs: trabalhos = works, pagina = page</em>
<blockquote>
Matched Rule: trabalhos/([^/]+)(/[0-9]+)?/?$
Matched Query: works=pagina&page=%2F2
Query String:
page=%2F2&name=pagina&post_type=works&works=pagina&debug-this=rewrites
</blockquote>
In my understanding, the URL <em>mysite.com/trabalhos/pagina/2</em> SHOULD point to the following URL (except it doesn't work - but If i replace 'trabalhos' with 'noticias' - my slug for 'blog' - it works):
<blockquote>
mysite.com/trabalhos/pagina/2/?pagename=trabalhos
</blockquote>
However, the URL <em>mysite.com/trabalhos/pagina/2</em> points to this weird url:
<blockquote>
mysite.com/trabalhos/pagina/2?page=%2F2&works=pagina&post_type=works&name=pagina
</blockquote>
And surprisingly, the following URL points exactly to the content I was expecting, that is, page 2 of works (trabalhos):
<blockquote>
mysite.com/noticias/pagina/2/?pagename=trabalhos
</blockquote>
I seem to be close to the solution...however I tried deactivating all plug-ins, removing almost all theme php code, each time reseting the permalinks settings in admin panel, among other things, and the error persists.
Is it some misconfiguration? Where would it be?
Thanks in advance for any help!
Regular post type pagination (blog) works correctly. Plus, everything else regarding my custom post type "works" seems to work fine.
My
Code:
template-works.php
<pre class="lang-php prettyprint-override">
Code:
get_home_pagination();
$args = array( 'post_type' => 'works', 'posts_per_page' => 10, 'paged' => $paged ); $wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
while ($wp_query->have_posts()) :
$wp_query->the_post();
get_template_part( 'loop', 'works' );
endwhile;
else:
_e( 'Nothing here.' );
endif;
Code:
template-blog.php
And then in
Code:
functions.php
<pre class="lang-php prettyprint-override">
Code:
function get_home_pagination() {
global $paged, $wp_query, $wp;
$args = wp_parse_args($wp->matched_query);
if ( !empty ( $args['paged'] ) && 0 == $paged ) {
$wp_query->set('paged', $args['paged']);
$paged = $args['paged'];
}
}
Code:
post-template.php
If I type, for example, the URL "(...)/blog/page/456", the blog template loads with the message "Nothing here". No 404 error page.
On the other hand, the URL "works/page/2", which I expect to return some posts, ends on a 404 error page.
Why?
<strong>EDIT:</strong>
On the 404 page I also get this error:
<blockquote>
Trying to get property of non-object in
(…)/wordpress/wp-includes/post-template.php on the line 29.
</blockquote>
...but it might not be related to the pagination problem. I managed to remove the code which causes this error (from a plug-in I customized) and the pagination still doesn't work.
<strong>EDIT:</strong>
This is what I got by debugging the URL <em>mysite.com/trabalhos/pagina/2</em> with the Debug-this plug-in. It seems to be very wrong:
<em>Obs: trabalhos = works, pagina = page</em>
<blockquote>
Matched Rule: trabalhos/([^/]+)(/[0-9]+)?/?$
Matched Query: works=pagina&page=%2F2
Query String:
page=%2F2&name=pagina&post_type=works&works=pagina&debug-this=rewrites
</blockquote>
In my understanding, the URL <em>mysite.com/trabalhos/pagina/2</em> SHOULD point to the following URL (except it doesn't work - but If i replace 'trabalhos' with 'noticias' - my slug for 'blog' - it works):
<blockquote>
mysite.com/trabalhos/pagina/2/?pagename=trabalhos
</blockquote>
However, the URL <em>mysite.com/trabalhos/pagina/2</em> points to this weird url:
<blockquote>
mysite.com/trabalhos/pagina/2?page=%2F2&works=pagina&post_type=works&name=pagina
</blockquote>
And surprisingly, the following URL points exactly to the content I was expecting, that is, page 2 of works (trabalhos):
<blockquote>
mysite.com/noticias/pagina/2/?pagename=trabalhos
</blockquote>
I seem to be close to the solution...however I tried deactivating all plug-ins, removing almost all theme php code, each time reseting the permalinks settings in admin panel, among other things, and the error persists.
Is it some misconfiguration? Where would it be?
Thanks in advance for any help!