0

I'm having trouble with my WPMU site that I hope you guys can help me with.

Anyway, here's the situation. For example, I'm on my site's category page. I clicked the next page, or any other page aside from page 1. I can view any pages fine. But if I copy, for example, page 2's url, open a new tab, paste the url, and hit Enter, instead of landing on the desired page, WP redirects me to a non-existent Sample Page.

I may have a few ideas as to why this is happening though, but I'm uncertain how to tackle the issue for me to fix it. Anyway, here's the part of the code that retrieves the posts in the category.php that I'm suspecting is the cause of this problem.

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

$the_query = array(
    'paged' => $paged,
    'cat' => $cat,
    'posts_per_page' => 20,
);

$arrgs = new WP_Query( $the_query );

$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $arrgs;

echo '<ul>';
while ( have_posts() ) : the_post();

    include(locate_template('content-category.php'));

endwhile;
echo '</ul>';

wp_reset_postdata();

echo '<div class="navi">';
    numeric_pagination('Previous', 'Next');
echo '</div>';

$wp_query = NULL;
$wp_query = $temp_query;

I am also suspecting the .htaccess, but I've little to no experience as to how that file works.

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Also, after a few more test runs, I've discovered something that hopefully is useful in solving my problem...

It seems that the problem only occurs if the url being copied has the category on it. Example: www.blog-wp.com/site1/category1 If I copy that example link and paste+go to the url, it loads fine, but then if I click to the next page, it redirects me to an unexisting sample page.

But... Example: www.blog-wp.com/site1/ If I copy that link and paste+go, it loads fine, then if I click the [category1] link, it sends me to [www.blog-wp.com/site1/category1], and I can click next page and any other pages fine.

So yeah... I'm confused.

Any help would be greatly appreciated. Thank you!

2
  • Do not replace the main query with a custom query on archive pages and the homepage, also, never nullify the main query, this is excatly the same as using query_posts. To solve this, remove the custom query and return to the normal main query using the default loop – Pieter Goosen Feb 27 '15 at 5:30
  • See this post :-) – Pieter Goosen Feb 27 '15 at 7:06
0

You should delete this part (as Pieter wrote):

$the_query = array(
    'paged' => $paged,
    'cat' => $cat,
    'posts_per_page' => 20,
);

$arrgs = new WP_Query( $the_query );

$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $arrgs;

I'm supposing that you want to show 20 posts per page, you could either configure that in Settings->Reading panel in the admin or do this:

query_posts($query_string . '&posts_per_page=20');

And then the query as it is.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.